+/* minigzip.c contains minimal changes required to be compiled with zlibWrapper:
+ * - #include "zlib.h" was changed to #include "zstd_zlibwrapper.h" */
+
/* minigzip.c -- simulate gzip using the zlib compression library
- * Copyright (C) 1995-2006, 2010, 2011, 2016 Jean-loup Gailly
- * For conditions of distribution and use, see copyright notice in zlib.h
+ * Copyright (C) 1995-2006, 2010, 2011 Jean-loup Gailly.
+ * For conditions of distribution and use, see https://www.zlib.net/zlib_license.html
*/
/*
/* @(#) $Id$ */
-#include "zlib.h"
+#define _POSIX_SOURCE /* fileno */
+
+#include "zstd_zlibwrapper.h"
#include <stdio.h>
#ifdef STDC
# define SET_BINARY_MODE(file)
#endif
-#if defined(_MSC_VER) && _MSC_VER < 1900
+#ifdef _MSC_VER
# define snprintf _snprintf
#endif
#if !defined(Z_HAVE_UNISTD_H) && !defined(_LARGEFILE64_SOURCE)
#ifndef WIN32 /* unlink already in stdio.h for WIN32 */
- extern int unlink OF((const char *));
+ extern int unlink _Z_OF((const char *));
#endif
#endif
# include <unistd.h> /* for unlink() */
#endif
-void *myalloc OF((void *, unsigned, unsigned));
-void myfree OF((void *, void *));
+void *myalloc _Z_OF((void *, unsigned, unsigned));
+void myfree _Z_OF((void *, void *));
void *myalloc(q, n, m)
void *q;
unsigned n, m;
{
- (void)q;
+ q = Z_NULL;
return calloc(n, m);
}
void myfree(q, p)
void *q, *p;
{
- (void)q;
+ q = Z_NULL;
free(p);
}
z_stream strm;
} *gzFile;
-gzFile gzopen OF((const char *, const char *));
-gzFile gzdopen OF((int, const char *));
-gzFile gz_open OF((const char *, int, const char *));
+gzFile gzopen _Z_OF((const char *, const char *));
+gzFile gzdopen _Z_OF((int, const char *));
+gzFile gz_open _Z_OF((const char *, int, const char *));
gzFile gzopen(path, mode)
const char *path;
return gz;
}
-int gzwrite OF((gzFile, const void *, unsigned));
+int gzwrite _Z_OF((gzFile, const void *, unsigned));
int gzwrite(gz, buf, len)
gzFile gz;
return len;
}
-int gzread OF((gzFile, void *, unsigned));
+int gzread _Z_OF((gzFile, void *, unsigned));
int gzread(gz, buf, len)
gzFile gz;
return len - strm->avail_out;
}
-int gzclose OF((gzFile));
+int gzclose _Z_OF((gzFile));
int gzclose(gz)
gzFile gz;
return Z_OK;
}
-const char *gzerror OF((gzFile, int *));
+const char *gzerror _Z_OF((gzFile, int *));
const char *gzerror(gz, err)
gzFile gz;
#endif
-static char *prog;
+char *prog;
-void error OF((const char *msg));
-void gz_compress OF((FILE *in, gzFile out));
+void error _Z_OF((const char *msg));
+void gz_compress _Z_OF((FILE *in, gzFile out));
#ifdef USE_MMAP
-int gz_compress_mmap OF((FILE *in, gzFile out));
+int gz_compress_mmap _Z_OF((FILE *in, gzFile out));
#endif
-void gz_uncompress OF((gzFile in, FILE *out));
-void file_compress OF((char *file, char *mode));
-void file_uncompress OF((char *file));
-int main OF((int argc, char *argv[]));
+void gz_uncompress _Z_OF((gzFile in, FILE *out));
+void file_compress _Z_OF((char *file, char *mode));
+void file_uncompress _Z_OF((char *file));
+int main _Z_OF((int argc, char *argv[]));
/* ===========================================================================
* Display error message and exit
exit(1);
}
-#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
- snprintf(outfile, sizeof(outfile), "%s%s", file, GZ_SUFFIX);
-#else
strcpy(outfile, file);
strcat(outfile, GZ_SUFFIX);
-#endif
in = fopen(file, "rb");
if (in == NULL) {
char *infile, *outfile;
FILE *out;
gzFile in;
- z_size_t len = strlen(file);
+ size_t len = strlen(file);
if (len + strlen(GZ_SUFFIX) >= sizeof(buf)) {
fprintf(stderr, "%s: filename too long\n", prog);
exit(1);
}
-#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
- snprintf(buf, sizeof(buf), "%s", file);
-#else
strcpy(buf, file);
-#endif
if (len > SUFFIX_LEN && strcmp(file+len-SUFFIX_LEN, GZ_SUFFIX) == 0) {
infile = file;
} else {
outfile = file;
infile = buf;
-#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
- snprintf(buf + len, sizeof(buf) - len, "%s", GZ_SUFFIX);
-#else
strcat(infile, GZ_SUFFIX);
-#endif
}
in = gzopen(infile, "rb");
if (in == NULL) {
gzFile file;
char *bname, outmode[20];
-#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
- snprintf(outmode, sizeof(outmode), "%s", "wb6 ");
-#else
strcpy(outmode, "wb6 ");
-#endif
prog = argv[0];
bname = strrchr(argv[0], '/');