]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Remove duplicate gz functions in test code (#348)
authorNathan Moinvaziri <nathan@nathanm.com>
Sat, 22 Jun 2019 07:25:39 +0000 (00:25 -0700)
committerHans Kristian Rosbach <hk-git@circlestorm.org>
Sat, 22 Jun 2019 07:25:39 +0000 (09:25 +0200)
Change CMakeLists.txt so that if WITH_GZFILEOP is OFF, gz* sources are still compiled against the tests which need them.
Remove duplicate gz functions from test code.
Always compile with gz functions when zlib tests enabled in makefile.

CMakeLists.txt
Makefile.in
test/example.c
test/fuzz/minigzip_fuzzer.c
test/minigzip.c

index deaae240f43c9405c4a93d1e7ed32a4d0f40dd67..e6af74114e6defa652f6a6d1827b33f44bbd9122 100644 (file)
@@ -709,18 +709,13 @@ set(ZLIB_SRCS
     uncompr.c
     zutil.c
 )
-if (WITH_GZFILEOP)
-    set(ZLIB_GZFILE_SRCS
-        gzclose.c
-        gzlib.c
-        gzread.c
-        gzwrite.c
-    )
-else (WITH_GZFILEOP)
-    set(ZLIB_GZFILE_SRCS
-    )
-endif (WITH_GZFILEOP)
 
+set(ZLIB_GZFILE_SRCS
+    gzclose.c
+    gzlib.c
+    gzread.c
+    gzwrite.c
+)
 
 if(NOT MINGW AND NOT MSYS)
     set(ZLIB_DLL_SRCS
@@ -744,11 +739,16 @@ if(MINGW OR MSYS)
     set(ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj)
 endif()
 
-add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_GZFILE_SRCS} ${ZLIB_ARCH_SRCS} ${ZLIB_ASMS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
+add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_ARCH_SRCS} ${ZLIB_ASMS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
 target_include_directories(zlib PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
-add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_GZFILE_SRCS} ${ZLIB_ARCH_SRCS} ${ZLIB_ASMS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
+add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_ARCH_SRCS} ${ZLIB_ASMS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
 target_include_directories(zlibstatic PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
 
+if(WITH_GZFILEOP)
+    target_sources(zlib PRIVATE ${ZLIB_GZFILE_SRCS})
+    target_sources(zlibstatic PRIVATE ${ZLIB_GZFILE_SRCS})
+endif()
+
 set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
 set_target_properties(zlib PROPERTIES SOVERSION 1)
 
@@ -807,21 +807,29 @@ endif()
 option(ZLIB_ENABLE_TESTS "Build test binaries" ON)
 if (ZLIB_ENABLE_TESTS)
     enable_testing()
+    macro(configure_test_executable target)
+        target_link_libraries(${target} zlib)
+        if(NOT WITH_GZFILEOP)
+            target_compile_definitions(${target} PUBLIC -DWITH_GZFILEOP)
+            target_sources(${target} PRIVATE ${ZLIB_GZFILE_SRCS})
+        endif()
+    endmacro()
+
     add_executable(example test/example.c)
-    target_link_libraries(example zlib)
+    configure_test_executable(example)
     add_test(NAME example COMMAND example${CMAKE_EXECUTABLE_SUFFIX})
 
     add_executable(minigzip test/minigzip.c)
-    target_link_libraries(minigzip zlib)
+    configure_test_executable(minigzip)
 
     if(HAVE_OFF64_T)
         add_executable(example64 test/example.c)
-        target_link_libraries(example64 zlib)
+        configure_test_executable(example64)
         set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
         add_test(NAME example64 COMMAND example64${CMAKE_EXECUTABLE_SUFFIX})
 
         add_executable(minigzip64 test/minigzip.c)
-        target_link_libraries(minigzip64 zlib)
+        configure_test_executable(minigzip64)
         set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
     endif()
 
@@ -830,7 +838,7 @@ if (ZLIB_ENABLE_TESTS)
         file(GLOB ALL_SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*")
         foreach(FUZZER ${FUZZERS})
             add_executable(${FUZZER}_fuzzer test/fuzz/${FUZZER}_fuzzer.c test/fuzz/standalone_fuzz_target_runner.c)
-            target_link_libraries(${FUZZER}_fuzzer zlib)
+            configure_test_executable(${FUZZER}_fuzzer)
             add_test(${FUZZER}_fuzzer ${FUZZER}_fuzzer${CMAKE_EXECUTABLE_SUFFIX} ${ALL_SRC_FILES})
         endforeach()
     endif()
index 1e8269522962dce6b06a2cbebeeb521347c0e420..69fe011658b60a07c7b518bd7168589d25352336 100644 (file)
@@ -147,7 +147,7 @@ example_flush_fuzzer.o:
 example_dict_fuzzer.o:
        $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
 minigzip_fuzzer.o:
-       $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
+       $(CC) $(CFLAGS) -DWITH_GZFILEOP $(INCLUDES) -c -o $@ $<
 checksum_fuzzer$(EXE): checksum_fuzzer.o standalone_fuzz_target_runner.o $(STATICLIB)
        $(CC) $(LDFLAGS) -o $@ $(LIB_FUZZING_ENGINE) checksum_fuzzer.o $(STATICLIB) -lpthread
 compress_fuzzer$(EXE): compress_fuzzer.o standalone_fuzz_target_runner.o $(STATICLIB)
@@ -160,8 +160,8 @@ example_flush_fuzzer$(EXE): example_flush_fuzzer.o standalone_fuzz_target_runner
        $(CC) $(LDFLAGS) -o $@ $(LIB_FUZZING_ENGINE) example_flush_fuzzer.o $(STATICLIB) -lpthread
 example_dict_fuzzer$(EXE): example_dict_fuzzer.o standalone_fuzz_target_runner.o $(STATICLIB)
        $(CC) $(LDFLAGS) -o $@ $(LIB_FUZZING_ENGINE) example_dict_fuzzer.o $(STATICLIB) -lpthread
-minigzip_fuzzer$(EXE): minigzip_fuzzer.o standalone_fuzz_target_runner.o $(STATICLIB)
-       $(CC) $(LDFLAGS) -o $@ $(LIB_FUZZING_ENGINE) minigzip_fuzzer.o $(STATICLIB) -lpthread
+minigzip_fuzzer$(EXE): minigzip_fuzzer.o standalone_fuzz_target_runner.o $(OBJG) $(STATICLIB)
+       $(CC) $(LDFLAGS) -o $@ $(LIB_FUZZING_ENGINE) minigzip_fuzzer.o $(OBJG) $(STATICLIB) -lpthread
 
 infcover.o: $(SRCDIR)/test/infcover.c $(SRCDIR)/zlib$(SUFFIX).h zconf$(SUFFIX).h
        $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/test/infcover.c
@@ -182,16 +182,16 @@ $(STATICLIB): $(OBJS)
        -@ ($(RANLIB) $@ || true) >/dev/null 2>&1
 
 example.o:
-       $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/test/example.c
+       $(CC) $(CFLAGS) -DWITH_GZFILEOP $(INCLUDES) -c -o $@ $(SRCDIR)/test/example.c
 
 minigzip.o:
-       $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/test/minigzip.c
+       $(CC) $(CFLAGS) -DWITH_GZFILEOP $(INCLUDES) -c -o $@ $(SRCDIR)/test/minigzip.c
 
 example64.o:
-       $(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 $(INCLUDES) -c -o $@ $(SRCDIR)/test/example.c
+       $(CC) $(CFLAGS) -DWITH_GZFILEOP -D_FILE_OFFSET_BITS=64 $(INCLUDES) -c -o $@ $(SRCDIR)/test/example.c
 
 minigzip64.o:
-       $(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 $(INCLUDES) -c -o $@ $(SRCDIR)/test/minigzip.c
+       $(CC) $(CFLAGS) -DWITH_GZFILEOP -D_FILE_OFFSET_BITS=64 $(INCLUDES) -c -o $@ $(SRCDIR)/test/minigzip.c
 
 zlibrc.o: win32/zlib$(SUFFIX)1.rc
        $(RC) $(RCFLAGS) -o $@ win32/zlib$(SUFFIX)1.rc
@@ -204,6 +204,9 @@ zlibrc.o: win32/zlib$(SUFFIX)1.rc
 %.lo: $(SRCDIR)/%.c
        $(CC) $(SFLAGS) -DPIC $(INCLUDES) -c -o $@ $<
 
+$(OBJG): %.o: $(SRCDIR)/%.c
+       $(CC) $(CFLAGS) -DWITH_GZFILEOP $(INCLUDES) -c -o $@ $<
+
 $(SHAREDTARGET): $(PIC_OBJS) $(DEFFILE) $(RCOBJS)
 ifneq ($(SHAREDTARGET),)
        $(LDSHARED) $(LDSHAREDFLAGS) $(LDFLAGS) -o $@ $(DEFFILE) $(PIC_OBJS) $(RCOBJS) $(LDSHAREDLIBC)
@@ -217,38 +220,38 @@ ifneq ($(SHAREDLIB),$(SHAREDTARGET))
 endif
 endif
 
-example$(EXE): example.o $(STATICLIB)
-       $(CC) $(LDFLAGS) -o $@ example.o $(TEST_LIBS) $(LDSHAREDLIBC)
+example$(EXE): example.o $(OBJG) $(STATICLIB)
+       $(CC) $(LDFLAGS) -o $@ example.o $(OBJG) $(TEST_LIBS) $(LDSHAREDLIBC)
 ifneq ($(STRIP),)
        $(STRIP) $@
 endif
 
-minigzip$(EXE): minigzip.o $(STATICLIB)
-       $(CC) $(LDFLAGS) -o $@ minigzip.o $(TEST_LIBS) $(LDSHAREDLIBC)
+minigzip$(EXE): minigzip.o $(OBJG) $(STATICLIB)
+       $(CC) $(LDFLAGS) -o $@ minigzip.o $(OBJG) $(TEST_LIBS) $(LDSHAREDLIBC)
 ifneq ($(STRIP),)
        $(STRIP) $@
 endif
 
-examplesh$(EXE): example.o $(SHAREDTARGET)
-       $(CC) $(LDFLAGS) -o $@ example.o $(SHAREDTARGET) $(LDSHAREDLIBC)
+examplesh$(EXE): example.o $(OBJG) $(SHAREDTARGET)
+       $(CC) $(LDFLAGS) -o $@ example.o $(OBJG) $(SHAREDTARGET) $(LDSHAREDLIBC)
 ifneq ($(STRIP),)
        $(STRIP) $@
 endif
 
-minigzipsh$(EXE): minigzip.o $(SHAREDTARGET)
-       $(CC) $(LDFLAGS) -o $@ minigzip.o $(SHAREDTARGET) $(LDSHAREDLIBC)
+minigzipsh$(EXE): minigzip.o $(OBJG) $(SHAREDTARGET)
+       $(CC) $(LDFLAGS) -o $@ minigzip.o $(OBJG) $(SHAREDTARGET) $(LDSHAREDLIBC)
 ifneq ($(STRIP),)
        $(STRIP) $@
 endif
 
-example64$(EXE): example64.o $(STATICLIB)
-       $(CC) $(LDFLAGS) -o $@ example64.o $(TEST_LIBS) $(LDSHAREDLIBC)
+example64$(EXE): example64.o $(OBJG) $(STATICLIB)
+       $(CC) $(LDFLAGS) -o $@ example64.o $(OBJG) $(TEST_LIBS) $(LDSHAREDLIBC)
 ifneq ($(STRIP),)
        $(STRIP) $@
 endif
 
-minigzip64$(EXE): minigzip64.o $(STATICLIB)
-       $(CC) $(LDFLAGS) -o $@ minigzip64.o $(TEST_LIBS) $(LDSHAREDLIBC)
+minigzip64$(EXE): minigzip64.o $(OBJG) $(STATICLIB)
+       $(CC) $(LDFLAGS) -o $@ minigzip64.o $(OBJG) $(TEST_LIBS) $(LDSHAREDLIBC)
 ifneq ($(STRIP),)
        $(STRIP) $@
 endif
index 13a828b72b884702d1cfdf9efd6f36471e505575..964a380d76551508f7b93e9f801ede9f3b7a8ea9 100644 (file)
@@ -35,6 +35,9 @@ static const char hello[] = "hello, hello!";
 static const char dictionary[] = "hello";
 static unsigned long dictId = 0; /* Adler32 value of the dictionary */
 
+
+void test_compress      (unsigned char *compr, z_size_t comprLen,unsigned char *uncompr, z_size_t uncomprLen);
+void test_gzio          (const char *fname, unsigned char *uncompr, z_size_t uncomprLen);
 void test_deflate       (unsigned char *compr, size_t comprLen);
 void test_inflate       (unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen);
 void test_large_deflate (unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen);
@@ -49,9 +52,6 @@ int  main               (int argc, char *argv[]);
 static alloc_func zalloc = NULL;
 static free_func zfree = NULL;
 
-void test_compress      (unsigned char *compr, z_size_t comprLen,
-                            unsigned char *uncompr, z_size_t uncomprLen);
-
 /* ===========================================================================
  * Test compress() and uncompress()
  */
@@ -76,10 +76,6 @@ void test_compress(unsigned char *compr, z_size_t comprLen, unsigned char *uncom
     }
 }
 
-#ifdef WITH_GZFILEOP
-void test_gzio          (const char *fname,
-                            unsigned char *uncompr, z_size_t uncomprLen);
-
 /* ===========================================================================
  * Test read/write of .gz files
  */
@@ -161,8 +157,6 @@ void test_gzio(const char *fname, unsigned char *uncompr, z_size_t uncomprLen)
 #endif
 }
 
-#endif /* WITH_GZFILEOP */
-
 /* ===========================================================================
  * Test deflate() with small buffers
  */
@@ -535,13 +529,8 @@ int main(int argc, char *argv[])
 
     test_compress(compr, comprLen, uncompr, uncomprLen);
 
-#ifdef WITH_GZFILEOP
     test_gzio((argc > 1 ? argv[1] : TESTFILE),
               uncompr, uncomprLen);
-#else
-    (void)argc;
-    (void)argv;
-#endif
 
     test_deflate(compr, comprLen);
     test_inflate(compr, comprLen, uncompr, uncomprLen);
index 73d25bb47a4a154120fe5529830aa97321069d0a..d0c35571f7ffaf78304f0e3721edc8ab22634e68 100644 (file)
 #define BUFLENW     (BUFLEN * 3) /* write buffer size */
 #define MAX_NAME_LEN 1024
 
-#ifndef WITH_GZFILEOP
-/* without WITH_GZFILEOP, create simplified gz* functions using deflate and inflate */
-
-#if defined(Z_HAVE_UNISTD_H) || defined(Z_LARGE)
-#  include <unistd.h>       /* for unlink() */
-#endif
-
-void *myalloc (void *, unsigned, unsigned);
-void myfree (void *, void *);
-
-void *myalloc(void *q, unsigned n, unsigned m)
-{
-    (void)q;
-#ifndef UNALIGNED_OK
-    return memalign(16, n * m);
-#else
-    return calloc(n, m);
-#endif
-}
-
-void myfree(void *q, void *p)
-{
-    (void)q;
-    free(p);
-}
-
-typedef struct gzFile_s {
-    FILE *file;
-    int write;
-    int err;
-    const char *msg;
-    PREFIX3(stream) strm;
-    unsigned char *buf;
-} *gzFile;
-
-gzFile PREFIX(gzopen)(const char *, const char *);
-gzFile PREFIX(gzdopen)(int, const char *);
-gzFile gz_open (const char *, int, const char *);
-
-gzFile PREFIX(gzopen)(const char *path, const char *mode)
-{
-    return gz_open(path, -1, mode);
-}
-
-gzFile PREFIX(gzdopen)(int fd, const char *mode)
-{
-    return gz_open(NULL, fd, mode);
-}
-
-gzFile gz_open(const char *path, int fd, const char *mode)
-{
-    gzFile gz;
-    int ret;
-    int level = Z_DEFAULT_COMPRESSION;
-    const char *plevel = mode;
-
-    gz = malloc(sizeof(struct gzFile_s));
-    if (gz == NULL)
-        return NULL;
-    gz->write = strchr(mode, 'w') != NULL;
-    gz->strm.zalloc = myalloc;
-    gz->strm.zfree = myfree;
-    gz->strm.opaque = NULL;
-    gz->buf = malloc(gz->write ? BUFLENW : BUFLEN);
-
-    if (gz->buf == NULL) {
-        free(gz);
-        return NULL;
-    }
-
-    while (*plevel) {
-        if (*plevel >= '0' && *plevel <= '9') {
-           level = *plevel - '0';
-           break;
-        }
-        plevel++;
-    }
-    if (gz->write)
-        ret = PREFIX(deflateInit2)(&(gz->strm), level, 8, 15 + 16, 8, 0);
-    else {
-        gz->strm.next_in = NULL;
-        gz->strm.avail_in = 0;
-        ret = PREFIX(inflateInit2)(&(gz->strm), 15 + 16);
-    }
-    if (ret != Z_OK) {
-        free(gz);
-        return NULL;
-    }
-#if _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE
-    gz->file = path == NULL ? fdopen(fd, gz->write ? "wb" : "rb")
-                            : fopen(path, gz->write ? "wb" : "rb");
-#else
-    /* fdopen is not available in C99. */
-    if (path == NULL)
-      exit(1);
-    gz->file = fopen(path, gz->write ? "wb" : "rb");
-#endif
-    if (gz->file == NULL) {
-        gz->write ? PREFIX(deflateEnd)(&(gz->strm)) : PREFIX(inflateEnd)(&(gz->strm));
-        free(gz);
-        return NULL;
-    }
-    gz->err = 0;
-    gz->msg = "";
-    return gz;
-}
-
-int PREFIX(gzwrite)(gzFile, const void *, unsigned);
-
-int PREFIX(gzwrite)(gzFile gz, const void *buf, unsigned len)
-{
-    PREFIX3(stream) *strm;
-
-    if (gz == NULL || !gz->write)
-        return 0;
-    strm = &(gz->strm);
-    strm->next_in = (void *)buf;
-    strm->avail_in = len;
-    do {
-        strm->next_out = gz->buf;
-        strm->avail_out = BUFLENW;
-        (void)PREFIX(deflate)(strm, Z_NO_FLUSH);
-        fwrite(gz->buf, 1, BUFLENW - strm->avail_out, gz->file);
-    } while (strm->avail_out == 0);
-    return len;
-}
-
-int PREFIX(gzread)(gzFile, void *, unsigned);
-
-int PREFIX(gzread)(gzFile gz, void *buf, unsigned len)
-{
-    PREFIX3(stream) *strm;
-
-    if (gz == NULL || gz->write || gz->err)
-        return 0;
-    strm = &(gz->strm);
-    strm->next_out = buf;
-    strm->avail_out = len;
-    do {
-        if (strm->avail_in == 0)
-        {
-            strm->next_in = gz->buf;
-            strm->avail_in = (uint32_t)fread(gz->buf, 1, BUFLEN, gz->file);
-        }
-        if (strm->avail_in > 0)
-        {
-            int ret = PREFIX(inflate)(strm, Z_NO_FLUSH);
-            if (ret == Z_DATA_ERROR) {
-                gz->err = ret;
-                gz->msg = strm->msg;
-                return 0;
-            }
-            else if (ret == Z_STREAM_END)
-                PREFIX(inflateReset)(strm);
-        }
-        else
-            break;
-    } while (strm->avail_out);
-    return len - strm->avail_out;
-}
-
-int PREFIX(gzclose)(gzFile);
-
-int PREFIX(gzclose)(gzFile gz)
-{
-    PREFIX3(stream) *strm;
-
-    if (gz == NULL)
-        return Z_STREAM_ERROR;
-    strm = &(gz->strm);
-    if (gz->write) {
-        strm->next_in = NULL;
-        strm->avail_in = 0;
-        do {
-            strm->next_out = gz->buf;
-            strm->avail_out = BUFLENW;
-            (void)PREFIX(deflate)(strm, Z_FINISH);
-            fwrite(gz->buf, 1, BUFLENW - strm->avail_out, gz->file);
-        } while (strm->avail_out == 0);
-        PREFIX(deflateEnd)(strm);
-    }
-    else
-        PREFIX(inflateEnd)(strm);
-    free(gz->buf);
-    fclose(gz->file);
-    free(gz);
-    return Z_OK;
-}
-
-const char *PREFIX(gzerror)(gzFile, int *);
-
-const char *PREFIX(gzerror)(gzFile gz, int *err)
-{
-    *err = gz->err;
-    return gz->msg;
-}
-
-#endif
-
 static char *prog;
 
 void error            (const char *msg);
index 67892d40068d0c0d817fdb06ca155761d282e549..ebbed9ae3ebf1f0ba73da869a22a41ccbae6b15b 100644 (file)
 #define BUFLENW     (BUFLEN * 3) /* write buffer size */
 #define MAX_NAME_LEN 1024
 
-#ifndef WITH_GZFILEOP
-/* without WITH_GZFILEOP, create simplified gz* functions using deflate and inflate */
-
-#if defined(Z_HAVE_UNISTD_H) || defined(Z_LARGE)
-#  include <unistd.h>       /* for unlink() */
-#endif
-
-void *myalloc (void *, unsigned, unsigned);
-void myfree (void *, void *);
-
-void *myalloc(void *q, unsigned n, unsigned m)
-{
-    (void)q;
-#ifndef UNALIGNED_OK
-    return memalign(16, n * m);
-#else
-    return calloc(n, m);
-#endif
-}
-
-void myfree(void *q, void *p)
-{
-    (void)q;
-    free(p);
-}
-
-typedef struct gzFile_s {
-    FILE *file;
-    int write;
-    int err;
-    const char *msg;
-    PREFIX3(stream) strm;
-    unsigned char *buf;
-} *gzFile;
-
-gzFile PREFIX(gzopen)(const char *, const char *);
-gzFile PREFIX(gzdopen)(int, const char *);
-gzFile gz_open (const char *, int, const char *);
-
-gzFile PREFIX(gzopen)(const char *path, const char *mode)
-{
-    return gz_open(path, -1, mode);
-}
-
-gzFile PREFIX(gzdopen)(int fd, const char *mode)
-{
-    return gz_open(NULL, fd, mode);
-}
-
-gzFile gz_open(const char *path, int fd, const char *mode)
-{
-    gzFile gz;
-    int ret;
-    int level = Z_DEFAULT_COMPRESSION;
-    const char *plevel = mode;
-
-    gz = malloc(sizeof(struct gzFile_s));
-    if (gz == NULL)
-        return NULL;
-    gz->write = strchr(mode, 'w') != NULL;
-    gz->strm.zalloc = myalloc;
-    gz->strm.zfree = myfree;
-    gz->strm.opaque = NULL;
-    gz->buf = malloc(gz->write ? BUFLENW : BUFLEN);
-
-    if (gz->buf == NULL) {
-        free(gz);
-        return NULL;
-    }
-
-    while (*plevel) {
-        if (*plevel >= '0' && *plevel <= '9') {
-           level = *plevel - '0';
-           break;
-        }
-        plevel++;
-    }
-    if (gz->write)
-        ret = PREFIX(deflateInit2)(&(gz->strm), level, 8, 15 + 16, 8, 0);
-    else {
-        gz->strm.next_in = NULL;
-        gz->strm.avail_in = 0;
-        ret = PREFIX(inflateInit2)(&(gz->strm), 15 + 16);
-    }
-    if (ret != Z_OK) {
-        free(gz);
-        return NULL;
-    }
-    gz->file = path == NULL ? fdopen(fd, gz->write ? "wb" : "rb") :
-                              fopen(path, gz->write ? "wb" : "rb");
-    if (gz->file == NULL) {
-        gz->write ? PREFIX(deflateEnd)(&(gz->strm)) : PREFIX(inflateEnd)(&(gz->strm));
-        free(gz);
-        return NULL;
-    }
-    gz->err = 0;
-    gz->msg = "";
-    return gz;
-}
-
-int PREFIX(gzwrite)(gzFile, const void *, unsigned);
-
-int PREFIX(gzwrite)(gzFile gz, const void *buf, unsigned len)
-{
-    PREFIX3(stream) *strm;
-
-    if (gz == NULL || !gz->write)
-        return 0;
-    strm = &(gz->strm);
-    strm->next_in = (void *)buf;
-    strm->avail_in = len;
-    do {
-        strm->next_out = gz->buf;
-        strm->avail_out = BUFLENW;
-        (void)PREFIX(deflate)(strm, Z_NO_FLUSH);
-        fwrite(gz->buf, 1, BUFLENW - strm->avail_out, gz->file);
-    } while (strm->avail_out == 0);
-    return len;
-}
-
-int PREFIX(gzread)(gzFile, void *, unsigned);
-
-int PREFIX(gzread)(gzFile gz, void *buf, unsigned len)
-{
-    PREFIX3(stream) *strm;
-
-    if (gz == NULL || gz->write || gz->err)
-        return 0;
-    strm = &(gz->strm);
-    strm->next_out = buf;
-    strm->avail_out = len;
-    do {
-        if (strm->avail_in == 0)
-        {
-            strm->next_in = gz->buf;
-            strm->avail_in = (uint32_t)fread(gz->buf, 1, BUFLEN, gz->file);
-        }
-        if (strm->avail_in > 0)
-        {
-            int ret = PREFIX(inflate)(strm, Z_NO_FLUSH);
-            if (ret == Z_DATA_ERROR) {
-                gz->err = ret;
-                gz->msg = strm->msg;
-                return 0;
-            }
-            else if (ret == Z_STREAM_END)
-                PREFIX(inflateReset)(strm);
-        }
-        else
-            break;
-    } while (strm->avail_out);
-    return len - strm->avail_out;
-}
-
-int PREFIX(gzclose)(gzFile);
-
-int PREFIX(gzclose)(gzFile gz)
-{
-    PREFIX3(stream) *strm;
-
-    if (gz == NULL)
-        return Z_STREAM_ERROR;
-    strm = &(gz->strm);
-    if (gz->write) {
-        strm->next_in = NULL;
-        strm->avail_in = 0;
-        do {
-            strm->next_out = gz->buf;
-            strm->avail_out = BUFLENW;
-            (void)PREFIX(deflate)(strm, Z_FINISH);
-            fwrite(gz->buf, 1, BUFLENW - strm->avail_out, gz->file);
-        } while (strm->avail_out == 0);
-        PREFIX(deflateEnd)(strm);
-    }
-    else
-        PREFIX(inflateEnd)(strm);
-    free(gz->buf);
-    fclose(gz->file);
-    free(gz);
-    return Z_OK;
-}
-
-const char *PREFIX(gzerror)(gzFile, int *);
-
-const char *PREFIX(gzerror)(gzFile gz, int *err)
-{
-    *err = gz->err;
-    return gz->msg;
-}
-
-#endif 
-
 static char *prog;
 
 void error            (const char *msg);