* For conditions of distribution and use, see copyright notice in zlib.h
*/
-/* @(#) $Id: example.c,v 1.2 2022/05/08 14:11:12 tb Exp $ */
+/* @(#) $Id: example.c,v 1.3 2023/11/18 22:40:14 tb Exp $ */
#include "zlib.h"
#include <stdio.h>
static const char dictionary[] = "hello";
static uLong dictId; /* Adler32 value of the dictionary */
-void test_deflate OF((Byte *compr, uLong comprLen));
-void test_inflate OF((Byte *compr, uLong comprLen,
- Byte *uncompr, uLong uncomprLen));
-void test_large_deflate OF((Byte *compr, uLong comprLen,
- Byte *uncompr, uLong uncomprLen));
-void test_large_inflate OF((Byte *compr, uLong comprLen,
- Byte *uncompr, uLong uncomprLen));
-void test_flush OF((Byte *compr, uLong *comprLen));
-void test_sync OF((Byte *compr, uLong comprLen,
- Byte *uncompr, uLong uncomprLen));
-void test_dict_deflate OF((Byte *compr, uLong comprLen));
-void test_dict_inflate OF((Byte *compr, uLong comprLen,
- Byte *uncompr, uLong uncomprLen));
-int main OF((int argc, char *argv[]));
-
-
#ifdef Z_SOLO
-void *myalloc OF((void *, unsigned, unsigned));
-void myfree OF((void *, void *));
-
-void *myalloc(q, n, m)
- void *q;
- unsigned n, m;
-{
+static void *myalloc(void *q, unsigned n, unsigned m) {
(void)q;
return calloc(n, m);
}
-void myfree(void *q, void *p)
-{
+static void myfree(void *q, void *p) {
(void)q;
free(p);
}
static alloc_func zalloc = (alloc_func)0;
static free_func zfree = (free_func)0;
-void test_compress OF((Byte *compr, uLong comprLen,
- Byte *uncompr, uLong uncomprLen));
-void test_gzio OF((const char *fname,
- Byte *uncompr, uLong uncomprLen));
-
/* ===========================================================================
* Test compress() and uncompress()
*/
-void test_compress(compr, comprLen, uncompr, uncomprLen)
- Byte *compr, *uncompr;
- uLong comprLen, uncomprLen;
-{
+static void test_compress(Byte *compr, uLong comprLen, Byte *uncompr,
+ uLong uncomprLen) {
int err;
uLong len = (uLong)strlen(hello)+1;
/* ===========================================================================
* Test read/write of .gz files
*/
-void test_gzio(fname, uncompr, uncomprLen)
- const char *fname; /* compressed file name */
- Byte *uncompr;
- uLong uncomprLen;
-{
+static void test_gzio(const char *fname, Byte *uncompr, uLong uncomprLen) {
#ifdef NO_GZCOMPRESS
fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n");
#else
/* ===========================================================================
* Test deflate() with small buffers
*/
-void test_deflate(compr, comprLen)
- Byte *compr;
- uLong comprLen;
-{
+static void test_deflate(Byte *compr, uLong comprLen) {
z_stream c_stream; /* compression stream */
int err;
uLong len = (uLong)strlen(hello)+1;
/* ===========================================================================
* Test inflate() with small buffers
*/
-void test_inflate(compr, comprLen, uncompr, uncomprLen)
- Byte *compr, *uncompr;
- uLong comprLen, uncomprLen;
-{
+static void test_inflate(Byte *compr, uLong comprLen, Byte *uncompr,
+ uLong uncomprLen) {
int err;
z_stream d_stream; /* decompression stream */
/* ===========================================================================
* Test deflate() with large buffers and dynamic change of compression level
*/
-void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
- Byte *compr, *uncompr;
- uLong comprLen, uncomprLen;
-{
+static void test_large_deflate(Byte *compr, uLong comprLen, Byte *uncompr,
+ uLong uncomprLen) {
z_stream c_stream; /* compression stream */
int err;
/* Feed in already compressed data and switch to no compression: */
deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY);
c_stream.next_in = compr;
- c_stream.avail_in = (uInt)comprLen/2;
+ c_stream.avail_in = (uInt)uncomprLen/2;
err = deflate(&c_stream, Z_NO_FLUSH);
CHECK_ERR(err, "deflate");
/* ===========================================================================
* Test inflate() with large buffers
*/
-void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
- Byte *compr, *uncompr;
- uLong comprLen, uncomprLen;
-{
+static void test_large_inflate(Byte *compr, uLong comprLen, Byte *uncompr,
+ uLong uncomprLen) {
int err;
z_stream d_stream; /* decompression stream */
err = inflateEnd(&d_stream);
CHECK_ERR(err, "inflateEnd");
- if (d_stream.total_out != 2*uncomprLen + comprLen/2) {
+ if (d_stream.total_out != 2*uncomprLen + uncomprLen/2) {
fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out);
exit(1);
} else {
/* ===========================================================================
* Test deflate() with full flush
*/
-void test_flush(compr, comprLen)
- Byte *compr;
- uLong *comprLen;
-{
+static void test_flush(Byte *compr, uLong *comprLen) {
z_stream c_stream; /* compression stream */
int err;
uInt len = (uInt)strlen(hello)+1;
/* ===========================================================================
* Test inflateSync()
*/
-void test_sync(compr, comprLen, uncompr, uncomprLen)
- Byte *compr, *uncompr;
- uLong comprLen, uncomprLen;
-{
+static void test_sync(Byte *compr, uLong comprLen, Byte *uncompr,
+ uLong uncomprLen) {
int err;
z_stream d_stream; /* decompression stream */
/* ===========================================================================
* Test deflate() with preset dictionary
*/
-void test_dict_deflate(compr, comprLen)
- Byte *compr;
- uLong comprLen;
-{
+static void test_dict_deflate(Byte *compr, uLong comprLen) {
z_stream c_stream; /* compression stream */
int err;
/* ===========================================================================
* Test inflate() with a preset dictionary
*/
-void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
- Byte *compr, *uncompr;
- uLong comprLen, uncomprLen;
-{
+static void test_dict_inflate(Byte *compr, uLong comprLen, Byte *uncompr,
+ uLong uncomprLen) {
int err;
z_stream d_stream; /* decompression stream */
* Usage: example [output.gz [input.gz]]
*/
-int main(argc, argv)
- int argc;
- char *argv[];
-{
+int main(int argc, char *argv[]) {
Byte *compr, *uncompr;
- uLong comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */
- uLong uncomprLen = comprLen;
+ uLong uncomprLen = 20000;
+ uLong comprLen = 3 * uncomprLen;
static const char* myVersion = ZLIB_VERSION;
if (zlibVersion()[0] != myVersion[0]) {
exit(1);
} else if (strcmp(zlibVersion(), ZLIB_VERSION) != 0) {
- fprintf(stderr, "warning: different zlib version\n");
+ fprintf(stderr, "warning: different zlib version linked: %s\n",
+ zlibVersion());
}
printf("zlib version %s = 0x%04x, compile flags = 0x%lx\n",
test_flush(compr, &comprLen);
test_sync(compr, comprLen, uncompr, uncomprLen);
- comprLen = uncomprLen;
+ comprLen = 3 * uncomprLen;
test_dict_deflate(compr, comprLen);
test_dict_inflate(compr, comprLen, uncompr, uncomprLen);
* or in pipe mode.
*/
-/* @(#) $Id: minigzip.c,v 1.1.1.1 2022/03/24 19:41:06 bluhm Exp $ */
+/* @(#) $Id: minigzip.c,v 1.2 2023/11/18 22:40:14 tb Exp $ */
#include "zlib.h"
#include <stdio.h>
#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(const char *);
#endif
#endif
# include <unistd.h> /* for unlink() */
#endif
-void *myalloc OF((void *, unsigned, unsigned));
-void myfree OF((void *, void *));
-
-void *myalloc(q, n, m)
- void *q;
- unsigned n, m;
-{
+static void *myalloc(void *q, unsigned n, unsigned m) {
(void)q;
return calloc(n, m);
}
-void myfree(q, p)
- void *q, *p;
-{
+static void myfree(void *q, void *p) {
(void)q;
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(path, mode)
-const char *path;
-const char *mode;
-{
- return gz_open(path, -1, mode);
-}
-
-gzFile gzdopen(fd, mode)
-int fd;
-const char *mode;
-{
- return gz_open(NULL, fd, mode);
-}
-
-gzFile gz_open(path, fd, mode)
- const char *path;
- int fd;
- const char *mode;
-{
+static gzFile gz_open(const char *path, int fd, const char *mode) {
gzFile gz;
int ret;
return gz;
}
-int gzwrite OF((gzFile, const void *, unsigned));
+static gzFile gzopen(const char *path, const char *mode) {
+ return gz_open(path, -1, mode);
+}
-int gzwrite(gz, buf, len)
- gzFile gz;
- const void *buf;
- unsigned len;
-{
+static gzFile gzdopen(int fd, const char *mode) {
+ return gz_open(NULL, fd, mode);
+}
+
+static int gzwrite(gzFile gz, const void *buf, unsigned len) {
z_stream *strm;
unsigned char out[BUFLEN];
return len;
}
-int gzread OF((gzFile, void *, unsigned));
-
-int gzread(gz, buf, len)
- gzFile gz;
- void *buf;
- unsigned len;
-{
+static int gzread(gzFile gz, void *buf, unsigned len) {
int ret;
unsigned got;
unsigned char in[1];
return len - strm->avail_out;
}
-int gzclose OF((gzFile));
-
-int gzclose(gz)
- gzFile gz;
-{
+static int gzclose(gzFile gz) {
z_stream *strm;
unsigned char out[BUFLEN];
return Z_OK;
}
-const char *gzerror OF((gzFile, int *));
-
-const char *gzerror(gz, err)
- gzFile gz;
- int *err;
-{
+static const char *gzerror(gzFile gz, int *err) {
*err = gz->err;
return gz->msg;
}
static char *prog;
-void error OF((const char *msg));
-void gz_compress OF((FILE *in, gzFile out));
-#ifdef USE_MMAP
-int gz_compress_mmap 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[]));
-
/* ===========================================================================
* Display error message and exit
*/
-void error(msg)
- const char *msg;
-{
+static void error(const char *msg) {
fprintf(stderr, "%s: %s\n", prog, msg);
exit(1);
}
-/* ===========================================================================
- * Compress input to output then close both files.
- */
-
-void gz_compress(in, out)
- FILE *in;
- gzFile out;
-{
- local char buf[BUFLEN];
- int len;
- int err;
-
-#ifdef USE_MMAP
- /* Try first compressing with mmap. If mmap fails (minigzip used in a
- * pipe), use the normal fread loop.
- */
- if (gz_compress_mmap(in, out) == Z_OK) return;
-#endif
- for (;;) {
- len = (int)fread(buf, 1, sizeof(buf), in);
- if (ferror(in)) {
- perror("fread");
- exit(1);
- }
- if (len == 0) break;
-
- if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err));
- }
- fclose(in);
- if (gzclose(out) != Z_OK) error("failed gzclose");
-}
-
#ifdef USE_MMAP /* MMAP version, Miguel Albrecht <malbrech@eso.org> */
/* Try compressing the input file at once using mmap. Return Z_OK if
* if success, Z_ERRNO otherwise.
*/
-int gz_compress_mmap(in, out)
- FILE *in;
- gzFile out;
-{
+static int gz_compress_mmap(FILE *in, gzFile out) {
int len;
int err;
int ifd = fileno(in);
}
#endif /* USE_MMAP */
+/* ===========================================================================
+ * Compress input to output then close both files.
+ */
+
+static void gz_compress(FILE *in, gzFile out) {
+ local char buf[BUFLEN];
+ int len;
+ int err;
+
+#ifdef USE_MMAP
+ /* Try first compressing with mmap. If mmap fails (minigzip used in a
+ * pipe), use the normal fread loop.
+ */
+ if (gz_compress_mmap(in, out) == Z_OK) return;
+#endif
+ for (;;) {
+ len = (int)fread(buf, 1, sizeof(buf), in);
+ if (ferror(in)) {
+ perror("fread");
+ exit(1);
+ }
+ if (len == 0) break;
+
+ if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err));
+ }
+ fclose(in);
+ if (gzclose(out) != Z_OK) error("failed gzclose");
+}
+
/* ===========================================================================
* Uncompress input to output then close both files.
*/
-void gz_uncompress(in, out)
- gzFile in;
- FILE *out;
-{
+static void gz_uncompress(gzFile in, FILE *out) {
local char buf[BUFLEN];
int len;
int err;
* Compress the given file: create a corresponding .gz file and remove the
* original.
*/
-void file_compress(file, mode)
- char *file;
- char *mode;
-{
+static void file_compress(char *file, char *mode) {
local char outfile[MAX_NAME_LEN];
FILE *in;
gzFile out;
/* ===========================================================================
* Uncompress the given file and remove the original.
*/
-void file_uncompress(file)
- char *file;
-{
+static void file_uncompress(char *file) {
local char buf[MAX_NAME_LEN];
char *infile, *outfile;
FILE *out;
gzFile in;
- unsigned len = strlen(file);
+ z_size_t len = strlen(file);
if (len + strlen(GZ_SUFFIX) >= sizeof(buf)) {
fprintf(stderr, "%s: filename too long\n", prog);
* -1 to -9 : compression level
*/
-int main(argc, argv)
- int argc;
- char *argv[];
-{
+int main(int argc, char *argv[]) {
int copyout = 0;
int uncompr = 0;
gzFile file;