Skip to content
Advertisement

Is -D_LARGEFILE_SOURCE needed on modern Linux

I’m looking at a very old C based project. It adds the -D_LARGEFILE_SOURCE define when building.

Is that preprocessor macro still needed on modern Linux (and if so, why)?

Advertisement

Answer

I checked the headers. If you are compiling for 64 bit, _LARGEFILE_SOURCE will be defined for you every time. This only does anything for 32 bit. And yes this is the switch, if you use modern 32 bit Linux, you still need it to access files > 2GB.

The macro definition changes the size of the file size parameters from 32 to 64 bit in lseek() and fseek(), changes the system call number for lseek() to call llseek(), and the size of the file size member of struct stat to 64 bit. (The syscall change happens elsewhere for *stat unless you still build against libc5.)

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement