madler / zlib

A massively spiffy yet delicately unobtrusive compression library.
http://zlib.net/
Other
5.58k stars 2.43k forks source link

zlib can't be compiled with Large File Support on 32-bit Linux #881

Closed claudiusaiz closed 7 months ago

claudiusaiz commented 9 months ago

I am using zlib version 1.3 and compiling for 32-bit Linux, nothing out of the ordinary.

When compiling zlib with default flags, I noticed it uses open instead of open64, making it incompatible with LFS:

$ nm libz.a | grep open     
00000445 T gzdopen
00000080 t gz_open
0000040f T gzopen
0000042a T gzopen64
         U open

I tried to pass it -D_FILE_OFFSET_BITS=64 through CMAKE_C_FLAGS but this still had no effect.

Looking through the code, I see that _FILE_OFFSET_BITS is explicitly undefined in gzguts.h:

#ifdef _LARGEFILE64_SOURCE
#  ifndef _LARGEFILE_SOURCE
#    define _LARGEFILE_SOURCE 1
#  endif
#  undef _FILE_OFFSET_BITS
#  undef _TIME_BITS
#endif

, since _LARGEFILE64_SOURCE is automatically defined by the project. So this would explain why passing _FILE_OFFSET_BITS didn't work.

So I have two questions regarding this: 1) Does anyone know what is the reason behind undefining _FILE_OFFSET_BITS? From my understanding, it should be able to coexist with _LARGEFILE64_SOURCE, since they have different purposes.

2) The open() call that leads to this is in gzlib.c: https://github.com/madler/zlib/blob/v1.3/gzlib.c#L235 The local function gz_open is called by both gzopen and gzopen64 (among others). Shouldn't gzopen64 use open64 instead?

Thanks

madler commented 7 months ago

zlib uses open() with O_LARGEFILE, which is equivalent to open64().