I've noticed some C projects compiling code which accesses files with _FILE_OFFSET_BITS=64
. Now, on my system (which is 64-bit), adding or removing this doesn't seem to do much - but perhaps on other systems it does.
When should I use _FILE_OFFSET_BITS=64
(or any other value for it)? Or, alternatively, what do I need to check to make sure that I don't actually need it?
Yes, do define it.
There is no drawback on using
-D_FILE_OFFSET_BITS=64
on a 64-bit platform. On 32-bit platform if you're doing something that could potentially need to seek/tell anything on files where the offsets exceed 2³¹, you need this one or be prepared to use the separate 64-bit functions.The reason why the behaviour isn't the default is that the C standard and POSIX specifies that
long int
be used for various functions - on 32-bit Unixen,long int
can usually hold a value up to 2³¹ only. Now, the use of-D_FILE_OFFSET_BITS=64
would guarantee that the code that useslseek
,ftello
etc, would continue to work in a 32-bit system as it would in a 64-bit system.Quoting GLibc feature test macros:
And
fseeko(3)
man pages: