• C

lseek vs fseek


i have a question regarding the difference between lseek and fseek. Is there a difference using lseek and fseek ? Thanks.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lseek is used with open/close/read/write system calls.
fseek is used with fopen/fgets/fread/fputs/fprintf etc. buffered I/O C-library calls They're a higher-level system of I/O that does its own buffering, and calls the lower-level calls to do the actual I/O.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zizi21Author Commented:
therefore, it doesn't mean that lseek is better than fseek or vice versa ? pls let me know if i have this wrong .thanks...
KuppingerCole Reviews AlgoSec in Executive Report

Leading analyst firm, KuppingerCole reviews AlgoSec's Security Policy Management Solution, and the security challenges faced by companies today in their Executive View report.

They're not interchangeable.  If you opened your file with fopen, so you have a FILE *, then you use fseek.  If you opened your file with open, so you have an int handle, then use lseek.
Another big difference is the number of files you're opening.  If you're opening more than 254 files (on *nix at least), then you can only use the open/close ... set.  If you try using the fopen/fclose set for more than 254 files, your program will just crash.

Having said that, it is a configurable option on *nix but it does warn of strange happenings if the figure is changed.  I don't know if this is a limit on Windows: the most I've ever used is 50.
evilrixSenior Software Engineer (Avast)Commented:
>> therefore, it doesn't mean that lseek is better than fseek or vice versa ?

lseek is a POSIX function, but it is not part of the C Standard, meaning code that uses this will only work on platforms that suppor it.

fseek is part of the C standard and will work on any platform.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.