[Webinar] Streamline your web hosting managementRegister Today


lseek vs fseek

Posted on 2010-04-09
Medium Priority
Last Modified: 2012-08-14

i have a question regarding the difference between lseek and fseek. Is there a difference using lseek and fseek ? Thanks.
Question by:zizi21
LVL 13

Accepted Solution

Superdave earned 1200 total points
ID: 30251246
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.

Author Comment

ID: 30265279
therefore, it doesn't mean that lseek is better than fseek or vice versa ? pls let me know if i have this wrong .thanks...
Become a Leader in Data Analytics

Gain the power to turn raw data into better business decisions and outcomes in your industry. Transform your career future by earning your MS in Data Analytics. WGU’s MSDA program curriculum features IT certifications from Oracle and SAS.  

LVL 13

Expert Comment

ID: 30267679
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.
LVL 11

Assisted Solution

cup earned 400 total points
ID: 30282202
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.
LVL 40

Assisted Solution

evilrix earned 400 total points
ID: 30285609
>> 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.

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question