tags:

views:

108

answers:

2

What's the difference between fgetpos/fsetpos and ftell/fseek? What are fgetpos and fsetpos good for?

+5  A: 

Well, from the manpage we can see that ftell and fseek use type long int to represent offsets (positions) in a file, and may therefore be limited to offsets which can be represented in a long int. (Type long int is not guaranteed to hold values larger than 2**31-1, limiting the maximum offset to 2 gigabytes). The newer fgetpos and fsetpos functions, on the other hand, use a special typedef, fpos_t, to represent the offsets. The type behind this typedef, if chosen appropriately, can represent arbitrarily large offsets, so fgetpos and fsetpos can be used with arbitrarily huge files. fgetpos and fsetpos also record the state associated with multibyte streams.

carlfilips
A: 

There is none functionally, although the interfaces are defined differently. They both are implemented because both are part of POSIX.

m1tk4
Both of these interfaces are from ISO C, not POSIX. And there are profound functional differences when the files get very large.
Zack