[Zlib-devel] Fix for building with _FILE_OFFSET_BITS=64
Mark Brown
broonie at sirena.org.uk
Sun May 30 11:25:56 EDT 2004
[Resend of a patch previously sent to zlib at gzip.org with some small
cleanups.]
On many 32 bit Unix platforms the size of off_t can be selected at build
time using the preprocessor define _FILE_OFFSET_BITS=64. Unfortunately,
z_off_t is part of the ABI for the file I/O functions of zlib and is
defined to be off_t so when a program built using _FILE_OFFSET_BITS=64
is linked against a zlib compiled without they will not agree on the
ABI.
This patch works around the issue by redefining the names of the file
I/O functions when building with _FILE_OFFSET_BITS=64 and then including
another copy of gzio.c built with that define in the library. This is
not precisely elegant but it does avoid the immediate problem while
maintaining API compatibility.
diff -urN zlib-1.2.1.1.orig/configure zlib-1.2.1.1/configure
--- zlib-1.2.1.1.orig/configure 2003-11-17 03:50:39.000000000 +0000
+++ zlib-1.2.1.1/configure 2004-05-22 19:39:40.000000000 +0100
@@ -35,6 +35,7 @@
gcc=0
old_cc="$CC"
old_cflags="$CFLAGS"
+OBJ64=
while test $# -ge 1
do
@@ -421,6 +422,24 @@
fi;;
esac
+cat > $test.c <<EOF
+#define _LARGEFILE64_SOURCE
+#include <stdio.h>
+
+int main(void)
+{
+ FILE *f = fopen64("filename", "r");
+ return 0;
+}
+
+EOF
+if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
+ echo Checking for LFS API support... Yes.
+ OBJ64=gzio64.o
+else
+ echo Checking for LFS API support... No.
+fi
+
rm -f $test.[co] $test $test$shared_ext
# udpate Makefile
@@ -442,4 +461,5 @@
/^includedir *=/s#=.*#=$includedir#
/^mandir *=/s#=.*#=$mandir#
/^LDFLAGS *=/s#=.*#=$LDFLAGS#
+/^OBJS64 *=/s#=.*#=$OBJ64#
" > Makefile
diff -urN zlib-1.2.1.1.orig/Makefile zlib-1.2.1.1/Makefile
--- zlib-1.2.1.1.orig/Makefile 2003-11-12 16:51:17.000000000 +0000
+++ zlib-1.2.1.1/Makefile 2004-05-22 19:39:46.000000000 +0100
@@ -52,6 +52,9 @@
OBJA =
# to use the asm code: make OBJA=match.o
+OBJ64 =
+# to build LFS versions of gzio make OBJ64=gzio64.o
+
TEST_OBJS = example.o minigzip.o
all: example$(EXE) minigzip$(EXE)
@@ -67,8 +70,8 @@
echo ' *** zlib test FAILED ***'; \
fi
-libz.a: $(OBJS) $(OBJA)
- $(AR) $@ $(OBJS) $(OBJA)
+libz.a: $(OBJS) $(OBJA) $(OBJ64)
+ $(AR) $@ $(OBJS) $(OBJA) $(OBJ64)
-@ ($(RANLIB) $@ || true) >/dev/null 2>&1
match.o: match.S
@@ -77,6 +80,9 @@
mv _match.o match.o
rm -f _match.s
+gzio64.o: gzio.o
+ $(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ gzio.c
+
$(SHAREDLIBV): $(OBJS)
$(LDSHARED) -o $@ $(OBJS)
rm -f $(SHAREDLIB) $(SHAREDLIBM)
diff -urN zlib-1.2.1.1.orig/Makefile.in zlib-1.2.1.1/Makefile.in
--- zlib-1.2.1.1.orig/Makefile.in 2003-11-12 16:51:17.000000000 +0000
+++ zlib-1.2.1.1/Makefile.in 2004-05-22 19:25:45.000000000 +0100
@@ -52,6 +52,9 @@
OBJA =
# to use the asm code: make OBJA=match.o
+OBJ64 =
+# to build LFS versions of gzio make OBJ64=gzio64.o
+
TEST_OBJS = example.o minigzip.o
all: example$(EXE) minigzip$(EXE)
@@ -67,8 +70,8 @@
echo ' *** zlib test FAILED ***'; \
fi
-libz.a: $(OBJS) $(OBJA)
- $(AR) $@ $(OBJS) $(OBJA)
+libz.a: $(OBJS) $(OBJA) $(OBJ64)
+ $(AR) $@ $(OBJS) $(OBJA) $(OBJ64)
-@ ($(RANLIB) $@ || true) >/dev/null 2>&1
match.o: match.S
@@ -77,6 +80,9 @@
mv _match.o match.o
rm -f _match.s
+gzio64.o: gzio.o
+ $(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ gzio.c
+
$(SHAREDLIBV): $(OBJS)
$(LDSHARED) -o $@ $(OBJS)
rm -f $(SHAREDLIB) $(SHAREDLIBM)
diff -urN zlib-1.2.1.1.orig/zconf.h zlib-1.2.1.1/zconf.h
--- zlib-1.2.1.1.orig/zconf.h 2003-11-04 22:54:53.000000000 +0000
+++ zlib-1.2.1.1/zconf.h 2004-05-22 22:17:47.000000000 +0100
@@ -282,6 +282,32 @@
# include <unixio.h> /* for off_t */
# endif
# define z_off_t off_t
+
+/* If we're building with LFS off_t then we need to link to the LFS
+ * versions of the stream access functions.
+ */
+# if (_FILE_OFFSET_BITS==64)
+# define gzopen gzopen64
+# define gzdopen gzdopen64
+# define gzsetparams gzsetparams64
+# define gzread gzread64
+# define gzwrite gzwrite64
+# define gzprintf gzprintf64
+# define gzputs gzputs64
+# define gzgets gzgets64
+# define gzputc gzputc64
+# define gzgetc gzgetc64
+# define gzungetc gzungetc64
+# define gzflush gzflush64
+# define gzseek gzseek64
+# define gzrewind gzrewind64
+# define gztell gztell64
+# define gzeof gzeof64
+# define gzclose gzclose64
+# define gzerror gzerror64
+# define gzclearerr gzclearerr64
+# endif
+
#endif
#ifndef SEEK_SET
# define SEEK_SET 0 /* Seek from beginning of file. */
diff -urN zlib-1.2.1.1.orig/zconf.in.h zlib-1.2.1.1/zconf.in.h
--- zlib-1.2.1.1.orig/zconf.in.h 2003-11-04 22:54:53.000000000 +0000
+++ zlib-1.2.1.1/zconf.in.h 2004-05-22 19:18:53.000000000 +0100
@@ -282,6 +282,32 @@
# include <unixio.h> /* for off_t */
# endif
# define z_off_t off_t
+
+/* If we're building with LFS off_t then we need to link to the LFS
+ * versions of the stream access functions.
+ */
+# if (_FILE_OFFSET_BITS==64)
+# define gzopen gzopen64
+# define gzdopen gzdopen64
+# define gzsetparams gzsetparams64
+# define gzread gzread64
+# define gzwrite gzwrite64
+# define gzprintf gzprintf64
+# define gzputs gzputs64
+# define gzgets gzgets64
+# define gzputc gzputc64
+# define gzgetc gzgetc64
+# define gzungetc gzungetc64
+# define gzflush gzflush64
+# define gzseek gzseek64
+# define gzrewind gzrewind64
+# define gztell gztell64
+# define gzeof gzeof64
+# define gzclose gzclose64
+# define gzerror gzerror64
+# define gzclearerr gzclearerr64
+# endif
+
#endif
#ifndef SEEK_SET
# define SEEK_SET 0 /* Seek from beginning of file. */
--
"You grabbed my hand and we fell into it, like a daydream - or a fever."
-------------- next part --------------
Binary files zlib-1.2.1.1.orig/a.out and zlib-1.2.1.1/a.out differ
diff -urN zlib-1.2.1.1.orig/configure zlib-1.2.1.1/configure
--- zlib-1.2.1.1.orig/configure 2003-11-17 03:50:39.000000000 +0000
+++ zlib-1.2.1.1/configure 2004-05-22 19:39:40.000000000 +0100
@@ -35,6 +35,7 @@
gcc=0
old_cc="$CC"
old_cflags="$CFLAGS"
+OBJ64=
while test $# -ge 1
do
@@ -421,6 +422,24 @@
fi;;
esac
+cat > $test.c <<EOF
+#define _LARGEFILE64_SOURCE
+#include <stdio.h>
+
+int main(void)
+{
+ FILE *f = fopen64("filename", "r");
+ return 0;
+}
+
+EOF
+if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
+ echo Checking for LFS API support... Yes.
+ OBJ64=gzio64.o
+else
+ echo Checking for LFS API support... No.
+fi
+
rm -f $test.[co] $test $test$shared_ext
# udpate Makefile
@@ -442,4 +461,5 @@
/^includedir *=/s#=.*#=$includedir#
/^mandir *=/s#=.*#=$mandir#
/^LDFLAGS *=/s#=.*#=$LDFLAGS#
+/^OBJS64 *=/s#=.*#=$OBJ64#
" > Makefile
diff -urN zlib-1.2.1.1.orig/Makefile zlib-1.2.1.1/Makefile
--- zlib-1.2.1.1.orig/Makefile 2003-11-12 16:51:17.000000000 +0000
+++ zlib-1.2.1.1/Makefile 2004-05-22 19:39:46.000000000 +0100
@@ -52,6 +52,9 @@
OBJA =
# to use the asm code: make OBJA=match.o
+OBJ64 =
+# to build LFS versions of gzio make OBJ64=gzio64.o
+
TEST_OBJS = example.o minigzip.o
all: example$(EXE) minigzip$(EXE)
@@ -67,8 +70,8 @@
echo ' *** zlib test FAILED ***'; \
fi
-libz.a: $(OBJS) $(OBJA)
- $(AR) $@ $(OBJS) $(OBJA)
+libz.a: $(OBJS) $(OBJA) $(OBJ64)
+ $(AR) $@ $(OBJS) $(OBJA) $(OBJ64)
-@ ($(RANLIB) $@ || true) >/dev/null 2>&1
match.o: match.S
@@ -77,6 +80,9 @@
mv _match.o match.o
rm -f _match.s
+gzio64.o: gzio.o
+ $(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ gzio.c
+
$(SHAREDLIBV): $(OBJS)
$(LDSHARED) -o $@ $(OBJS)
rm -f $(SHAREDLIB) $(SHAREDLIBM)
diff -urN zlib-1.2.1.1.orig/Makefile.in zlib-1.2.1.1/Makefile.in
--- zlib-1.2.1.1.orig/Makefile.in 2003-11-12 16:51:17.000000000 +0000
+++ zlib-1.2.1.1/Makefile.in 2004-05-22 19:25:45.000000000 +0100
@@ -52,6 +52,9 @@
OBJA =
# to use the asm code: make OBJA=match.o
+OBJ64 =
+# to build LFS versions of gzio make OBJ64=gzio64.o
+
TEST_OBJS = example.o minigzip.o
all: example$(EXE) minigzip$(EXE)
@@ -67,8 +70,8 @@
echo ' *** zlib test FAILED ***'; \
fi
-libz.a: $(OBJS) $(OBJA)
- $(AR) $@ $(OBJS) $(OBJA)
+libz.a: $(OBJS) $(OBJA) $(OBJ64)
+ $(AR) $@ $(OBJS) $(OBJA) $(OBJ64)
-@ ($(RANLIB) $@ || true) >/dev/null 2>&1
match.o: match.S
@@ -77,6 +80,9 @@
mv _match.o match.o
rm -f _match.s
+gzio64.o: gzio.o
+ $(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ gzio.c
+
$(SHAREDLIBV): $(OBJS)
$(LDSHARED) -o $@ $(OBJS)
rm -f $(SHAREDLIB) $(SHAREDLIBM)
diff -urN zlib-1.2.1.1.orig/zconf.h zlib-1.2.1.1/zconf.h
--- zlib-1.2.1.1.orig/zconf.h 2003-11-04 22:54:53.000000000 +0000
+++ zlib-1.2.1.1/zconf.h 2004-05-22 22:17:47.000000000 +0100
@@ -282,6 +282,32 @@
# include <unixio.h> /* for off_t */
# endif
# define z_off_t off_t
+
+/* If we're building with LFS off_t then we need to link to the LFS
+ * versions of the stream access functions.
+ */
+# if (_FILE_OFFSET_BITS==64)
+# define gzopen gzopen64
+# define gzdopen gzdopen64
+# define gzsetparams gzsetparams64
+# define gzread gzread64
+# define gzwrite gzwrite64
+# define gzprintf gzprintf64
+# define gzputs gzputs64
+# define gzgets gzgets64
+# define gzputc gzputc64
+# define gzgetc gzgetc64
+# define gzungetc gzungetc64
+# define gzflush gzflush64
+# define gzseek gzseek64
+# define gzrewind gzrewind64
+# define gztell gztell64
+# define gzeof gzeof64
+# define gzclose gzclose64
+# define gzerror gzerror64
+# define gzclearerr gzclearerr64
+# endif
+
#endif
#ifndef SEEK_SET
# define SEEK_SET 0 /* Seek from beginning of file. */
diff -urN zlib-1.2.1.1.orig/zconf.in.h zlib-1.2.1.1/zconf.in.h
--- zlib-1.2.1.1.orig/zconf.in.h 2003-11-04 22:54:53.000000000 +0000
+++ zlib-1.2.1.1/zconf.in.h 2004-05-22 19:18:53.000000000 +0100
@@ -282,6 +282,32 @@
# include <unixio.h> /* for off_t */
# endif
# define z_off_t off_t
+
+/* If we're building with LFS off_t then we need to link to the LFS
+ * versions of the stream access functions.
+ */
+# if (_FILE_OFFSET_BITS==64)
+# define gzopen gzopen64
+# define gzdopen gzdopen64
+# define gzsetparams gzsetparams64
+# define gzread gzread64
+# define gzwrite gzwrite64
+# define gzprintf gzprintf64
+# define gzputs gzputs64
+# define gzgets gzgets64
+# define gzputc gzputc64
+# define gzgetc gzgetc64
+# define gzungetc gzungetc64
+# define gzflush gzflush64
+# define gzseek gzseek64
+# define gzrewind gzrewind64
+# define gztell gztell64
+# define gzeof gzeof64
+# define gzclose gzclose64
+# define gzerror gzerror64
+# define gzclearerr gzclearerr64
+# endif
+
#endif
#ifndef SEEK_SET
# define SEEK_SET 0 /* Seek from beginning of file. */
More information about the Zlib-devel
mailing list