Not quite. Clues can be found from Beej:
On virtually every system (and certainly every system that I know of),
people don't use these functions, using ftell() and fseek() instead.
These functions exist just in case your system can't remember file
positions as a simple byte offset.
And Linux man pages:
On some non-UNIX systems, an fpos_t object may be a complex object and
these routines may be the only way to portably reposition a text
stream.
And on Windows:
It assumes that any \n character in the buffer was originally a \r\n
sequence that had been normalized when the data was read into the
buffer.
That is to say, files that aren't (Windows-linebreak) text files go wrong in Windows when opened in text mode because fsetpos
is assuming the file really was a (Windows-linebreak) text file and therefore cannot contain a \n
with no \r
.
The C11 standard says (my emphasis):
7.21.2/6:
Each wide-oriented stream has an associated mbstate_t object that
stores the current parse state of the stream. A successful call to
fgetpos stores a representation of the value of this mbstate_t object
as part of the value of the fpos_t object. A later successful call to
fsetpos using the same stored fpos_t value restores the value of the
associated mbstate_t object as well as the position within the
controlled stream.
Note that fseek
and ftell
have nothing to say about the mbstate_t
object: they do not report or restore it. So on wide-oriented streams (that is to say, streams on which you've used wide-oriented I/O functions) they only reset the file position, not (if the implementation actually has more than one possible value of a mbstate_t
object) the whole state of the stream.
Wide-oriented streams aren't the same thing as text streams, it's just that reading wide text files is the common use for them. Actually fseek
and ftell
are documented to be able to reset the file position on text files, provided you use them correctly. So I believe (I might be wrong) that fsetpos
and fgetpos
are only required when using wide I/O functions on the stream.