From what I know the standard posix functions ftell and fseek *must* return a 32 bits integer (posix standard).
***** So this is not a bug *****
The wrap-around that you see is the expected overflow when using that functions on large files, and doesn't have any relation with signed or unsigned.
Dear frankie,
I'm quoting ftell()'s description from the latest documentation of (the original) GCC...
long int ftell (FILE *stream) [Function]
This function returns the current file position of the stream stream. This function can fail if the stream doesn’t support file positioning, or if the file position can’t be represented in a long int, and possibly for other reasons as well. If a failure occurs, a value of -1 is returned.
Moreover, please have a look at The Open Group Base Specifications 2008 documentation of ftell(), at this address:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/ftell.html#tag_16_202, where it is clearly stated that...
a) what is described it complies to the ISO C standard
b) the return value of -1 casted to
long along with setting errno to EOVERFLOW is set when ftell() is asked for a file offset that cannot be represented correctly in an object of type long (it is in the ERRORS section).
The same holds for fseek():
http://pubs.opengroup.org/onlinepubs/9699919799/functions/fseek.html#tag_16_196 (again check the ERRORS section).
Pelles C's implementation of those function does not comply to those specifications, so I think it makes sense to considered them buggy.
All the compilers, included PellesC, have 64 bits extensions: _ftell64, fsetpos, fgetpos, _ftello and _fseeko. But they are not C99 standard functions.
I'm aware of that, but imagine the nightmare of redefining in the pre-processor non-standard function names, types, and constants for every compiler/platform implementation. If one takes that route, it will be extremely painful to write/maintain the code, even for only the most popular compilers/platforms.
The behaviour of MINGW32, that use GCC, and M$ are *not* standard, so are *not platform agnostic*.
But at the very least they do return a negative value on overflows, they don't wrap around.
I suggest to use _ftello and _fseeko that uses 64 bits offsets, they are not C99 standard, but almost all compilers have.
NB in GCC using the switch "gcc -D_FILE_OFFSET_BITS=64" fseek and ftell use 64 bits offsets for files larger than 2Gb, *but this is not standard behaviour for C nor for POSIX*.
This fall to my prvious response above. To give just an example, check this out:
a) gcc: off64_t ftello64 (FILE *stream)
b) lcc-win: long long ftelli64(FILE *);
c) pelles c:
?? (I don't seem to find the suggested _ftell64() in the documentation)
Even if _ftell64() does exist (perhaps named differently) imagine what it takes to maintain code that tries to use them abstractly.