aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2011-10-07 01:57:07 -0700
committerMark Adler <madler@alumni.caltech.edu>2011-10-07 02:11:56 -0700
commitf442c1e89e99ae5a0068a2d32e7284c2623f09fd (patch)
tree1bc659f486af707673c36916c4d75ef7f517dece
parent518ad0177ae2f1aaefc49285b3536a6bd8d9973c (diff)
downloadzlib-f442c1e89e99ae5a0068a2d32e7284c2623f09fd.tar.gz
zlib-f442c1e89e99ae5a0068a2d32e7284c2623f09fd.tar.bz2
zlib-f442c1e89e99ae5a0068a2d32e7284c2623f09fd.zip
Add a ./config --solo option to make zlib subset with no libary use
A common request has been the ability to compile zlib to require no other libraries. This --solo option provides that ability. The price is that the gz*, compress*, and uncompress functions are eliminated, and that the user must provide memory allocation and free routines to deflate and inflate when initializing.
-rw-r--r--Makefile.in10
-rwxr-xr-xconfigure16
-rw-r--r--deflate.c19
-rw-r--r--example.c76
-rw-r--r--infback.c11
-rw-r--r--inflate.c15
-rw-r--r--minigzip.c193
-rw-r--r--zconf.h106
-rw-r--r--zconf.h.cmakein106
-rw-r--r--zconf.h.in106
-rw-r--r--zlib.h16
-rw-r--r--zutil.c7
-rw-r--r--zutil.h51
13 files changed, 537 insertions, 195 deletions
diff --git a/Makefile.in b/Makefile.in
index 67375ef..c1c37fe 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -54,11 +54,13 @@ man3dir = ${mandir}/man3
54pkgconfigdir = ${libdir}/pkgconfig 54pkgconfigdir = ${libdir}/pkgconfig
55tempfile := $(shell mktemp -u __XXXXXX) 55tempfile := $(shell mktemp -u __XXXXXX)
56 56
57OBJC = adler32.o compress.o crc32.o deflate.o gzclose.o gzlib.o gzread.o \ 57OBJZ = adler32.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.o trees.o zutil.o
58 gzwrite.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o 58OBJG = compress.o uncompr.o gzclose.o gzlib.o gzread.o gzwrite.o
59OBJC = $(OBJZ) $(OBJG)
59 60
60PIC_OBJC = adler32.lo compress.lo crc32.lo deflate.lo gzclose.lo gzlib.lo gzread.lo \ 61PIC_OBJZ = adler32.lo crc32.lo deflate.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo zutil.lo
61 gzwrite.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo uncompr.lo zutil.lo 62PIC_OBJG = compress.lo uncompr.lo gzclose.lo gzlib.lo gzread.lo gzwrite.lo
63PIC_OBJC = $(PIC_OBJZ) $(PIC_OBJG)
62 64
63# to use the asm code: make OBJA=match.o, PIC_OBJA=match.lo 65# to use the asm code: make OBJA=match.o, PIC_OBJA=match.lo
64OBJA = 66OBJA =
diff --git a/configure b/configure
index 1838846..672b24f 100755
--- a/configure
+++ b/configure
@@ -54,11 +54,14 @@ includedir=${includedir-'${prefix}/include'}
54mandir=${mandir-'${prefix}/share/man'} 54mandir=${mandir-'${prefix}/share/man'}
55shared_ext='.so' 55shared_ext='.so'
56shared=1 56shared=1
57solo=0
57zprefix=0 58zprefix=0
58build64=0 59build64=0
59gcc=0 60gcc=0
60old_cc="$CC" 61old_cc="$CC"
61old_cflags="$CFLAGS" 62old_cflags="$CFLAGS"
63OBJC='$(OBJZ) $(OBJG)'
64PIC_OBJC='$(PIC_OBJZ) $(PIC_OBJG)'
62 65
63while test $# -ge 1 66while test $# -ge 1
64do 67do
@@ -81,6 +84,7 @@ case "$1" in
81 -i* | --includedir) includedir="$2"; shift; shift ;; 84 -i* | --includedir) includedir="$2"; shift; shift ;;
82 -s* | --shared | --enable-shared) shared=1; shift ;; 85 -s* | --shared | --enable-shared) shared=1; shift ;;
83 -t | --static) shared=0; shift ;; 86 -t | --static) shared=0; shift ;;
87 --solo) solo=1; shift ;;
84 -z* | --zprefix) zprefix=1; shift ;; 88 -z* | --zprefix) zprefix=1; shift ;;
85 -6* | --64) build64=1; shift ;; 89 -6* | --64) build64=1; shift ;;
86 -a*=* | --archs=*) ARCHS=`echo $1 | sed 's/.*=//'`; shift ;; 90 -a*=* | --archs=*) ARCHS=`echo $1 | sed 's/.*=//'`; shift ;;
@@ -331,6 +335,16 @@ if test $zprefix -eq 1; then
331 echo "Using z_ prefix on all symbols." 335 echo "Using z_ prefix on all symbols."
332fi 336fi
333 337
338if test $solo -eq 1; then
339 sed '/#define ZCONF_H/a\
340#define Z_SOLO
341
342' < zconf.h > zconf.temp.h
343 mv zconf.temp.h zconf.h
344OBJC='$(OBJZ)'
345PIC_OBJC='$(PIC_OBJZ)'
346fi
347
334cat > $test.c <<EOF 348cat > $test.c <<EOF
335#include <stdio.h> 349#include <stdio.h>
336#include <stdarg.h> 350#include <stdarg.h>
@@ -589,6 +603,8 @@ sed < Makefile.in "
589/^sharedlibdir *=/s#=.*#=$sharedlibdir# 603/^sharedlibdir *=/s#=.*#=$sharedlibdir#
590/^includedir *=/s#=.*#=$includedir# 604/^includedir *=/s#=.*#=$includedir#
591/^mandir *=/s#=.*#=$mandir# 605/^mandir *=/s#=.*#=$mandir#
606/^OBJC *=/s#=.*#= $OBJC#
607/^PIC_OBJC *=/s#=.*#= $PIC_OBJC#
592/^all: */s#:.*#: $ALL# 608/^all: */s#:.*#: $ALL#
593/^test: */s#:.*#: $TEST# 609/^test: */s#:.*#: $TEST#
594" > Makefile 610" > Makefile
diff --git a/deflate.c b/deflate.c
index b126a71..4b8e91b 100644
--- a/deflate.c
+++ b/deflate.c
@@ -235,10 +235,19 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
235 235
236 strm->msg = Z_NULL; 236 strm->msg = Z_NULL;
237 if (strm->zalloc == (alloc_func)0) { 237 if (strm->zalloc == (alloc_func)0) {
238#ifdef Z_SOLO
239 return Z_STREAM_ERROR;
240#else
238 strm->zalloc = zcalloc; 241 strm->zalloc = zcalloc;
239 strm->opaque = (voidpf)0; 242 strm->opaque = (voidpf)0;
243#endif
240 } 244 }
241 if (strm->zfree == (free_func)0) strm->zfree = zcfree; 245 if (strm->zfree == (free_func)0)
246#ifdef Z_SOLO
247 return Z_STREAM_ERROR;
248#else
249 strm->zfree = zcfree;
250#endif
242 251
243#ifdef FASTEST 252#ifdef FASTEST
244 if (level != 0) level = 1; 253 if (level != 0) level = 1;
@@ -957,12 +966,12 @@ int ZEXPORT deflateCopy (dest, source)
957 966
958 ss = source->state; 967 ss = source->state;
959 968
960 zmemcpy(dest, source, sizeof(z_stream)); 969 zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
961 970
962 ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state)); 971 ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
963 if (ds == Z_NULL) return Z_MEM_ERROR; 972 if (ds == Z_NULL) return Z_MEM_ERROR;
964 dest->state = (struct internal_state FAR *) ds; 973 dest->state = (struct internal_state FAR *) ds;
965 zmemcpy(ds, ss, sizeof(deflate_state)); 974 zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state));
966 ds->strm = dest; 975 ds->strm = dest;
967 976
968 ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); 977 ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
@@ -978,8 +987,8 @@ int ZEXPORT deflateCopy (dest, source)
978 } 987 }
979 /* following zmemcpy do not work for 16-bit MSDOS */ 988 /* following zmemcpy do not work for 16-bit MSDOS */
980 zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte)); 989 zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
981 zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos)); 990 zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
982 zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos)); 991 zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
983 zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); 992 zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
984 993
985 ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); 994 ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
diff --git a/example.c b/example.c
index c15cc03..f515a48 100644
--- a/example.c
+++ b/example.c
@@ -34,10 +34,6 @@ const char hello[] = "hello, hello!";
34const char dictionary[] = "hello"; 34const char dictionary[] = "hello";
35uLong dictId; /* Adler32 value of the dictionary */ 35uLong dictId; /* Adler32 value of the dictionary */
36 36
37void test_compress OF((Byte *compr, uLong comprLen,
38 Byte *uncompr, uLong uncomprLen));
39void test_gzio OF((const char *fname,
40 Byte *uncompr, uLong uncomprLen));
41void test_deflate OF((Byte *compr, uLong comprLen)); 37void test_deflate OF((Byte *compr, uLong comprLen));
42void test_inflate OF((Byte *compr, uLong comprLen, 38void test_inflate OF((Byte *compr, uLong comprLen,
43 Byte *uncompr, uLong uncomprLen)); 39 Byte *uncompr, uLong uncomprLen));
@@ -53,6 +49,39 @@ void test_dict_inflate OF((Byte *compr, uLong comprLen,
53 Byte *uncompr, uLong uncomprLen)); 49 Byte *uncompr, uLong uncomprLen));
54int main OF((int argc, char *argv[])); 50int main OF((int argc, char *argv[]));
55 51
52
53#ifdef Z_SOLO
54
55void *myalloc OF((void *, unsigned, unsigned));
56void myfree OF((void *, void *));
57
58void *myalloc(q, n, m)
59 void *q;
60 unsigned n, m;
61{
62 q = Z_NULL;
63 return calloc(n, m);
64}
65
66void myfree(void *q, void *p)
67{
68 q = Z_NULL;
69 free(p);
70}
71
72static alloc_func zalloc = myalloc;
73static free_func zfree = myfree;
74
75#else /* !Z_SOLO */
76
77static alloc_func zalloc = (alloc_func)0;
78static free_func zfree = (free_func)0;
79
80void test_compress OF((Byte *compr, uLong comprLen,
81 Byte *uncompr, uLong uncomprLen));
82void test_gzio OF((const char *fname,
83 Byte *uncompr, uLong uncomprLen));
84
56/* =========================================================================== 85/* ===========================================================================
57 * Test compress() and uncompress() 86 * Test compress() and uncompress()
58 */ 87 */
@@ -163,6 +192,8 @@ void test_gzio(fname, uncompr, uncomprLen)
163#endif 192#endif
164} 193}
165 194
195#endif /* Z_SOLO */
196
166/* =========================================================================== 197/* ===========================================================================
167 * Test deflate() with small buffers 198 * Test deflate() with small buffers
168 */ 199 */
@@ -174,8 +205,8 @@ void test_deflate(compr, comprLen)
174 int err; 205 int err;
175 uLong len = (uLong)strlen(hello)+1; 206 uLong len = (uLong)strlen(hello)+1;
176 207
177 c_stream.zalloc = (alloc_func)0; 208 c_stream.zalloc = zalloc;
178 c_stream.zfree = (free_func)0; 209 c_stream.zfree = zfree;
179 c_stream.opaque = (voidpf)0; 210 c_stream.opaque = (voidpf)0;
180 211
181 err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION); 212 err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
@@ -213,8 +244,8 @@ void test_inflate(compr, comprLen, uncompr, uncomprLen)
213 244
214 strcpy((char*)uncompr, "garbage"); 245 strcpy((char*)uncompr, "garbage");
215 246
216 d_stream.zalloc = (alloc_func)0; 247 d_stream.zalloc = zalloc;
217 d_stream.zfree = (free_func)0; 248 d_stream.zfree = zfree;
218 d_stream.opaque = (voidpf)0; 249 d_stream.opaque = (voidpf)0;
219 250
220 d_stream.next_in = compr; 251 d_stream.next_in = compr;
@@ -252,8 +283,8 @@ void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
252 z_stream c_stream; /* compression stream */ 283 z_stream c_stream; /* compression stream */
253 int err; 284 int err;
254 285
255 c_stream.zalloc = (alloc_func)0; 286 c_stream.zalloc = zalloc;
256 c_stream.zfree = (free_func)0; 287 c_stream.zfree = zfree;
257 c_stream.opaque = (voidpf)0; 288 c_stream.opaque = (voidpf)0;
258 289
259 err = deflateInit(&c_stream, Z_BEST_SPEED); 290 err = deflateInit(&c_stream, Z_BEST_SPEED);
@@ -309,8 +340,8 @@ void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
309 340
310 strcpy((char*)uncompr, "garbage"); 341 strcpy((char*)uncompr, "garbage");
311 342
312 d_stream.zalloc = (alloc_func)0; 343 d_stream.zalloc = zalloc;
313 d_stream.zfree = (free_func)0; 344 d_stream.zfree = zfree;
314 d_stream.opaque = (voidpf)0; 345 d_stream.opaque = (voidpf)0;
315 346
316 d_stream.next_in = compr; 347 d_stream.next_in = compr;
@@ -349,8 +380,8 @@ void test_flush(compr, comprLen)
349 int err; 380 int err;
350 uInt len = (uInt)strlen(hello)+1; 381 uInt len = (uInt)strlen(hello)+1;
351 382
352 c_stream.zalloc = (alloc_func)0; 383 c_stream.zalloc = zalloc;
353 c_stream.zfree = (free_func)0; 384 c_stream.zfree = zfree;
354 c_stream.opaque = (voidpf)0; 385 c_stream.opaque = (voidpf)0;
355 386
356 err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION); 387 err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
@@ -388,8 +419,8 @@ void test_sync(compr, comprLen, uncompr, uncomprLen)
388 419
389 strcpy((char*)uncompr, "garbage"); 420 strcpy((char*)uncompr, "garbage");
390 421
391 d_stream.zalloc = (alloc_func)0; 422 d_stream.zalloc = zalloc;
392 d_stream.zfree = (free_func)0; 423 d_stream.zfree = zfree;
393 d_stream.opaque = (voidpf)0; 424 d_stream.opaque = (voidpf)0;
394 425
395 d_stream.next_in = compr; 426 d_stream.next_in = compr;
@@ -430,8 +461,8 @@ void test_dict_deflate(compr, comprLen)
430 z_stream c_stream; /* compression stream */ 461 z_stream c_stream; /* compression stream */
431 int err; 462 int err;
432 463
433 c_stream.zalloc = (alloc_func)0; 464 c_stream.zalloc = zalloc;
434 c_stream.zfree = (free_func)0; 465 c_stream.zfree = zfree;
435 c_stream.opaque = (voidpf)0; 466 c_stream.opaque = (voidpf)0;
436 467
437 err = deflateInit(&c_stream, Z_BEST_COMPRESSION); 468 err = deflateInit(&c_stream, Z_BEST_COMPRESSION);
@@ -469,8 +500,8 @@ void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
469 500
470 strcpy((char*)uncompr, "garbage"); 501 strcpy((char*)uncompr, "garbage");
471 502
472 d_stream.zalloc = (alloc_func)0; 503 d_stream.zalloc = zalloc;
473 d_stream.zfree = (free_func)0; 504 d_stream.zfree = zfree;
474 d_stream.opaque = (voidpf)0; 505 d_stream.opaque = (voidpf)0;
475 506
476 d_stream.next_in = compr; 507 d_stream.next_in = compr;
@@ -540,10 +571,15 @@ int main(argc, argv)
540 printf("out of memory\n"); 571 printf("out of memory\n");
541 exit(1); 572 exit(1);
542 } 573 }
574
575#ifdef Z_SOLO
576 argc = strlen(argv[0]);
577#else
543 test_compress(compr, comprLen, uncompr, uncomprLen); 578 test_compress(compr, comprLen, uncompr, uncomprLen);
544 579
545 test_gzio((argc > 1 ? argv[1] : TESTFILE), 580 test_gzio((argc > 1 ? argv[1] : TESTFILE),
546 uncompr, uncomprLen); 581 uncompr, uncomprLen);
582#endif
547 583
548 test_deflate(compr, comprLen); 584 test_deflate(compr, comprLen);
549 test_inflate(compr, comprLen, uncompr, uncomprLen); 585 test_inflate(compr, comprLen, uncompr, uncomprLen);
diff --git a/infback.c b/infback.c
index af3a8c9..5462952 100644
--- a/infback.c
+++ b/infback.c
@@ -42,10 +42,19 @@ int stream_size;
42 return Z_STREAM_ERROR; 42 return Z_STREAM_ERROR;
43 strm->msg = Z_NULL; /* in case we return an error */ 43 strm->msg = Z_NULL; /* in case we return an error */
44 if (strm->zalloc == (alloc_func)0) { 44 if (strm->zalloc == (alloc_func)0) {
45#ifdef Z_SOLO
46 return Z_STREAM_ERROR;
47#else
45 strm->zalloc = zcalloc; 48 strm->zalloc = zcalloc;
46 strm->opaque = (voidpf)0; 49 strm->opaque = (voidpf)0;
50#endif
47 } 51 }
48 if (strm->zfree == (free_func)0) strm->zfree = zcfree; 52 if (strm->zfree == (free_func)0)
53#ifdef Z_SOLO
54 return Z_STREAM_ERROR;
55#else
56 strm->zfree = zcfree;
57#endif
49 state = (struct inflate_state FAR *)ZALLOC(strm, 1, 58 state = (struct inflate_state FAR *)ZALLOC(strm, 1,
50 sizeof(struct inflate_state)); 59 sizeof(struct inflate_state));
51 if (state == Z_NULL) return Z_MEM_ERROR; 60 if (state == Z_NULL) return Z_MEM_ERROR;
diff --git a/inflate.c b/inflate.c
index dd880c4..cf10b01 100644
--- a/inflate.c
+++ b/inflate.c
@@ -180,10 +180,19 @@ int stream_size;
180 if (strm == Z_NULL) return Z_STREAM_ERROR; 180 if (strm == Z_NULL) return Z_STREAM_ERROR;
181 strm->msg = Z_NULL; /* in case we return an error */ 181 strm->msg = Z_NULL; /* in case we return an error */
182 if (strm->zalloc == (alloc_func)0) { 182 if (strm->zalloc == (alloc_func)0) {
183#ifdef Z_SOLO
184 return Z_STREAM_ERROR;
185#else
183 strm->zalloc = zcalloc; 186 strm->zalloc = zcalloc;
184 strm->opaque = (voidpf)0; 187 strm->opaque = (voidpf)0;
188#endif
185 } 189 }
186 if (strm->zfree == (free_func)0) strm->zfree = zcfree; 190 if (strm->zfree == (free_func)0)
191#ifdef Z_SOLO
192 return Z_STREAM_ERROR;
193#else
194 strm->zfree = zcfree;
195#endif
187 state = (struct inflate_state FAR *) 196 state = (struct inflate_state FAR *)
188 ZALLOC(strm, 1, sizeof(struct inflate_state)); 197 ZALLOC(strm, 1, sizeof(struct inflate_state));
189 if (state == Z_NULL) return Z_MEM_ERROR; 198 if (state == Z_NULL) return Z_MEM_ERROR;
@@ -1433,8 +1442,8 @@ z_streamp source;
1433 } 1442 }
1434 1443
1435 /* copy state */ 1444 /* copy state */
1436 zmemcpy(dest, source, sizeof(z_stream)); 1445 zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
1437 zmemcpy(copy, state, sizeof(struct inflate_state)); 1446 zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state));
1438 if (state->lencode >= state->codes && 1447 if (state->lencode >= state->codes &&
1439 state->lencode <= state->codes + ENOUGH - 1) { 1448 state->lencode <= state->codes + ENOUGH - 1) {
1440 copy->lencode = copy->codes + (state->lencode - state->codes); 1449 copy->lencode = copy->codes + (state->lencode - state->codes);
diff --git a/minigzip.c b/minigzip.c
index 9825ccc..8317344 100644
--- a/minigzip.c
+++ b/minigzip.c
@@ -1,5 +1,5 @@
1/* minigzip.c -- simulate gzip using the zlib compression library 1/* minigzip.c -- simulate gzip using the zlib compression library
2 * Copyright (C) 1995-2006, 2010 Jean-loup Gailly. 2 * Copyright (C) 1995-2006, 2010, 2011 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
@@ -138,6 +138,197 @@ static void pwinerror (s)
138# define local 138# define local
139#endif 139#endif
140 140
141#ifdef Z_SOLO
142/* for Z_SOLO, create simplified gz* functions using deflate and inflate */
143
144#if defined(Z_HAVE_UNISTD_H) || defined(Z_LARGE)
145# include <unistd.h> /* for unlink() */
146#endif
147
148void *myalloc OF((void *, unsigned, unsigned));
149void myfree OF((void *, void *));
150
151void *myalloc(q, n, m)
152 void *q;
153 unsigned n, m;
154{
155 q = Z_NULL;
156 return calloc(n, m);
157}
158
159void myfree(q, p)
160 void *q, *p;
161{
162 q = Z_NULL;
163 free(p);
164}
165
166typedef struct gzFile_s {
167 FILE *file;
168 int write;
169 int err;
170 char *msg;
171 z_stream strm;
172} *gzFile;
173
174gzFile gzopen OF((const char *, const char *));
175gzFile gzdopen OF((int, const char *));
176gzFile gz_open OF((const char *, int, const char *));
177
178gzFile gzopen(path, mode)
179const char *path;
180const char *mode;
181{
182 return gz_open(path, -1, mode);
183}
184
185gzFile gzdopen(fd, mode)
186int fd;
187const char *mode;
188{
189 return gz_open(NULL, fd, mode);
190}
191
192gzFile gz_open(path, fd, mode)
193 const char *path;
194 int fd;
195 const char *mode;
196{
197 gzFile gz;
198 int ret;
199
200 gz = malloc(sizeof(gzFile));
201 if (gz == NULL)
202 return NULL;
203 gz->write = strchr(mode, 'w') != NULL;
204 gz->strm.zalloc = myalloc;
205 gz->strm.zfree = myfree;
206 gz->strm.opaque = Z_NULL;
207 if (gz->write)
208 ret = deflateInit2(&(gz->strm), -1, 8, 15 + 16, 8, 0);
209 else {
210 gz->strm.next_in = 0;
211 gz->strm.avail_in = Z_NULL;
212 ret = inflateInit2(&(gz->strm), 15 + 16);
213 }
214 if (ret != Z_OK) {
215 free(gz);
216 return NULL;
217 }
218 gz->file = path == NULL ? fdopen(fd, gz->write ? "wb" : "rb") :
219 fopen(path, gz->write ? "wb" : "rb");
220 if (gz->file == NULL) {
221 gz->write ? deflateEnd(&(gz->strm)) : inflateEnd(&(gz->strm));
222 free(gz);
223 return NULL;
224 }
225 gz->err = 0;
226 gz->msg = "";
227 return gz;
228}
229
230int gzwrite OF((gzFile, const void *, unsigned));
231
232int gzwrite(gz, buf, len)
233 gzFile gz;
234 const void *buf;
235 unsigned len;
236{
237 z_stream *strm;
238 unsigned char out[BUFLEN];
239
240 if (gz == NULL || !gz->write)
241 return 0;
242 strm = &(gz->strm);
243 strm->next_in = (void *)buf;
244 strm->avail_in = len;
245 do {
246 strm->next_out = out;
247 strm->avail_out = BUFLEN;
248 (void)deflate(strm, Z_NO_FLUSH);
249 fwrite(out, 1, BUFLEN - strm->avail_out, gz->file);
250 } while (strm->avail_out == 0);
251 return len;
252}
253
254int gzread OF((gzFile, void *, unsigned));
255
256int gzread(gz, buf, len)
257 gzFile gz;
258 void *buf;
259 unsigned len;
260{
261 int ret;
262 unsigned got;
263 unsigned char in[1];
264 z_stream *strm;
265
266 if (gz == NULL || gz->write)
267 return 0;
268 if (gz->err)
269 return 0;
270 strm = &(gz->strm);
271 strm->next_out = (void *)buf;
272 strm->avail_out = len;
273 do {
274 got = fread(in, 1, 1, gz->file);
275 if (got == 0)
276 break;
277 strm->next_in = in;
278 strm->avail_in = 1;
279 ret = inflate(strm, Z_NO_FLUSH);
280 if (ret == Z_DATA_ERROR) {
281 gz->err = Z_DATA_ERROR;
282 gz->msg = strm->msg;
283 return 0;
284 }
285 if (ret == Z_STREAM_END)
286 inflateReset(strm);
287 } while (strm->avail_out);
288 return len - strm->avail_out;
289}
290
291int gzclose OF((gzFile));
292
293int gzclose(gz)
294 gzFile gz;
295{
296 z_stream *strm;
297 unsigned char out[BUFLEN];
298
299 if (gz == NULL)
300 return Z_STREAM_ERROR;
301 strm = &(gz->strm);
302 if (gz->write) {
303 strm->next_in = Z_NULL;
304 strm->avail_in = 0;
305 do {
306 strm->next_out = out;
307 strm->avail_out = BUFLEN;
308 (void)deflate(strm, Z_FINISH);
309 fwrite(out, 1, BUFLEN - strm->avail_out, gz->file);
310 } while (strm->avail_out == 0);
311 deflateEnd(strm);
312 }
313 else
314 inflateEnd(strm);
315 fclose(gz->file);
316 free(gz);
317 return Z_OK;
318}
319
320const char *gzerror OF((gzFile, int *));
321
322const char *gzerror(gz, err)
323 gzFile gz;
324 int *err;
325{
326 *err = gz->err;
327 return gz->msg;
328}
329
330#endif
331
141char *prog; 332char *prog;
142 333
143void error OF((const char *msg)); 334void error OF((const char *msg));
diff --git a/zconf.h b/zconf.h
index bcb7615..ed16b06 100644
--- a/zconf.h
+++ b/zconf.h
@@ -28,9 +28,11 @@
28# define adler32 z_adler32 28# define adler32 z_adler32
29# define adler32_combine z_adler32_combine 29# define adler32_combine z_adler32_combine
30# define adler32_combine64 z_adler32_combine64 30# define adler32_combine64 z_adler32_combine64
31# define compress z_compress 31# ifndef Z_SOLO
32# define compress2 z_compress2 32# define compress z_compress
33# define compressBound z_compressBound 33# define compress2 z_compress2
34# define compressBound z_compressBound
35# endif
34# define crc32 z_crc32 36# define crc32 z_crc32
35# define crc32_combine z_crc32_combine 37# define crc32_combine z_crc32_combine
36# define crc32_combine64 z_crc32_combine64 38# define crc32_combine64 z_crc32_combine64
@@ -49,39 +51,41 @@
49# define deflateTune z_deflateTune 51# define deflateTune z_deflateTune
50# define deflate_copyright z_deflate_copyright 52# define deflate_copyright z_deflate_copyright
51# define get_crc_table z_get_crc_table 53# define get_crc_table z_get_crc_table
52# define gz_error z_gz_error 54# ifndef Z_SOLO
53# define gz_intmax z_gz_intmax 55# define gz_error z_gz_error
54# define gz_strwinerror z_gz_strwinerror 56# define gz_intmax z_gz_intmax
55# define gzbuffer z_gzbuffer 57# define gz_strwinerror z_gz_strwinerror
56# define gzclearerr z_gzclearerr 58# define gzbuffer z_gzbuffer
57# define gzclose z_gzclose 59# define gzclearerr z_gzclearerr
58# define gzclose_r z_gzclose_r 60# define gzclose z_gzclose
59# define gzclose_w z_gzclose_w 61# define gzclose_r z_gzclose_r
60# define gzdirect z_gzdirect 62# define gzclose_w z_gzclose_w
61# define gzdopen z_gzdopen 63# define gzdirect z_gzdirect
62# define gzeof z_gzeof 64# define gzdopen z_gzdopen
63# define gzerror z_gzerror 65# define gzeof z_gzeof
64# define gzflags z_gzflags 66# define gzerror z_gzerror
65# define gzflush z_gzflush 67# define gzflags z_gzflags
66# define gzgetc z_gzgetc 68# define gzflush z_gzflush
67# define gzgetc_ z_gzgetc_ 69# define gzgetc z_gzgetc
68# define gzgets z_gzgets 70# define gzgetc_ z_gzgetc_
69# define gzoffset z_gzoffset 71# define gzgets z_gzgets
70# define gzoffset64 z_gzoffset64 72# define gzoffset z_gzoffset
71# define gzopen z_gzopen 73# define gzoffset64 z_gzoffset64
72# define gzopen64 z_gzopen64 74# define gzopen z_gzopen
73# define gzprintf z_gzprintf 75# define gzopen64 z_gzopen64
74# define gzputc z_gzputc 76# define gzprintf z_gzprintf
75# define gzputs z_gzputs 77# define gzputc z_gzputc
76# define gzread z_gzread 78# define gzputs z_gzputs
77# define gzrewind z_gzrewind 79# define gzread z_gzread
78# define gzseek z_gzseek 80# define gzrewind z_gzrewind
79# define gzseek64 z_gzseek64 81# define gzseek z_gzseek
80# define gzsetparams z_gzsetparams 82# define gzseek64 z_gzseek64
81# define gztell z_gztell 83# define gzsetparams z_gzsetparams
82# define gztell64 z_gztell64 84# define gztell z_gztell
83# define gzungetc z_gzungetc 85# define gztell64 z_gztell64
84# define gzwrite z_gzwrite 86# define gzungetc z_gzungetc
87# define gzwrite z_gzwrite
88# endif
85# define inflate z_inflate 89# define inflate z_inflate
86# define inflateBack z_inflateBack 90# define inflateBack z_inflateBack
87# define inflateBackEnd z_inflateBackEnd 91# define inflateBackEnd z_inflateBackEnd
@@ -102,10 +106,14 @@
102# define inflate_copyright z_inflate_copyright 106# define inflate_copyright z_inflate_copyright
103# define inflate_fast z_inflate_fast 107# define inflate_fast z_inflate_fast
104# define inflate_table z_inflate_table 108# define inflate_table z_inflate_table
105# define uncompress z_uncompress 109# ifndef Z_SOLO
110# define uncompress z_uncompress
111# endif
106# define zError z_zError 112# define zError z_zError
107# define zcalloc z_zcalloc 113# ifndef Z_SOLO
108# define zcfree z_zcfree 114# define zcalloc z_zcalloc
115# define zcfree z_zcfree
116# endif
109# define zlibCompileFlags z_zlibCompileFlags 117# define zlibCompileFlags z_zlibCompileFlags
110# define zlibVersion z_zlibVersion 118# define zlibVersion z_zlibVersion
111 119
@@ -115,9 +123,11 @@
115# define alloc_func z_alloc_func 123# define alloc_func z_alloc_func
116# define charf z_charf 124# define charf z_charf
117# define free_func z_free_func 125# define free_func z_free_func
118# define gzFile z_gzFile 126# ifndef Z_SOLO
119# define gz_header z_gz_header 127# define gzFile z_gzFile
120# define gz_headerp z_gz_headerp 128# define gz_header z_gz_header
129# define gz_headerp z_gz_headerp
130# endif
121# define in_func z_in_func 131# define in_func z_in_func
122# define intf z_intf 132# define intf z_intf
123# define out_func z_out_func 133# define out_func z_out_func
@@ -130,7 +140,9 @@
130# define voidpf z_voidpf 140# define voidpf z_voidpf
131 141
132/* all zlib structs in zlib.h and zconf.h */ 142/* all zlib structs in zlib.h and zconf.h */
133# define gz_header_s z_gz_header_s 143# ifndef Z_SOLO
144# define gz_header_s z_gz_header_s
145# endif
134# define internal_state z_internal_state 146# define internal_state z_internal_state
135 147
136#endif 148#endif
@@ -377,7 +389,9 @@ typedef uLong FAR uLongf;
377#endif 389#endif
378 390
379#ifdef STDC 391#ifdef STDC
380# include <sys/types.h> /* for off_t */ 392# ifndef Z_SOLO
393# include <sys/types.h> /* for off_t */
394# endif
381#endif 395#endif
382 396
383/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and 397/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
@@ -394,7 +408,7 @@ typedef uLong FAR uLongf;
394# define Z_LARGE 408# define Z_LARGE
395#endif 409#endif
396 410
397#if defined(Z_HAVE_UNISTD_H) || defined(Z_LARGE) 411#if (defined(Z_HAVE_UNISTD_H) || defined(Z_LARGE)) && !defined(Z_SOLO)
398# include <unistd.h> /* for SEEK_* and off_t */ 412# include <unistd.h> /* for SEEK_* and off_t */
399# ifdef VMS 413# ifdef VMS
400# include <unixio.h> /* for off_t */ 414# include <unixio.h> /* for off_t */
@@ -404,7 +418,7 @@ typedef uLong FAR uLongf;
404# endif 418# endif
405#endif 419#endif
406 420
407#ifndef SEEK_SET 421#if !defined(SEEK_SET) && !defined(Z_SOLO)
408# define SEEK_SET 0 /* Seek from beginning of file. */ 422# define SEEK_SET 0 /* Seek from beginning of file. */
409# define SEEK_CUR 1 /* Seek from current position. */ 423# define SEEK_CUR 1 /* Seek from current position. */
410# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ 424# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
diff --git a/zconf.h.cmakein b/zconf.h.cmakein
index 29680aa..84e4680 100644
--- a/zconf.h.cmakein
+++ b/zconf.h.cmakein
@@ -30,9 +30,11 @@
30# define adler32 z_adler32 30# define adler32 z_adler32
31# define adler32_combine z_adler32_combine 31# define adler32_combine z_adler32_combine
32# define adler32_combine64 z_adler32_combine64 32# define adler32_combine64 z_adler32_combine64
33# define compress z_compress 33# ifndef Z_SOLO
34# define compress2 z_compress2 34# define compress z_compress
35# define compressBound z_compressBound 35# define compress2 z_compress2
36# define compressBound z_compressBound
37# endif
36# define crc32 z_crc32 38# define crc32 z_crc32
37# define crc32_combine z_crc32_combine 39# define crc32_combine z_crc32_combine
38# define crc32_combine64 z_crc32_combine64 40# define crc32_combine64 z_crc32_combine64
@@ -51,39 +53,41 @@
51# define deflateTune z_deflateTune 53# define deflateTune z_deflateTune
52# define deflate_copyright z_deflate_copyright 54# define deflate_copyright z_deflate_copyright
53# define get_crc_table z_get_crc_table 55# define get_crc_table z_get_crc_table
54# define gz_error z_gz_error 56# ifndef Z_SOLO
55# define gz_intmax z_gz_intmax 57# define gz_error z_gz_error
56# define gz_strwinerror z_gz_strwinerror 58# define gz_intmax z_gz_intmax
57# define gzbuffer z_gzbuffer 59# define gz_strwinerror z_gz_strwinerror
58# define gzclearerr z_gzclearerr 60# define gzbuffer z_gzbuffer
59# define gzclose z_gzclose 61# define gzclearerr z_gzclearerr
60# define gzclose_r z_gzclose_r 62# define gzclose z_gzclose
61# define gzclose_w z_gzclose_w 63# define gzclose_r z_gzclose_r
62# define gzdirect z_gzdirect 64# define gzclose_w z_gzclose_w
63# define gzdopen z_gzdopen 65# define gzdirect z_gzdirect
64# define gzeof z_gzeof 66# define gzdopen z_gzdopen
65# define gzerror z_gzerror 67# define gzeof z_gzeof
66# define gzflags z_gzflags 68# define gzerror z_gzerror
67# define gzflush z_gzflush 69# define gzflags z_gzflags
68# define gzgetc z_gzgetc 70# define gzflush z_gzflush
69# define gzgetc_ z_gzgetc_ 71# define gzgetc z_gzgetc
70# define gzgets z_gzgets 72# define gzgetc_ z_gzgetc_
71# define gzoffset z_gzoffset 73# define gzgets z_gzgets
72# define gzoffset64 z_gzoffset64 74# define gzoffset z_gzoffset
73# define gzopen z_gzopen 75# define gzoffset64 z_gzoffset64
74# define gzopen64 z_gzopen64 76# define gzopen z_gzopen
75# define gzprintf z_gzprintf 77# define gzopen64 z_gzopen64
76# define gzputc z_gzputc 78# define gzprintf z_gzprintf
77# define gzputs z_gzputs 79# define gzputc z_gzputc
78# define gzread z_gzread 80# define gzputs z_gzputs
79# define gzrewind z_gzrewind 81# define gzread z_gzread
80# define gzseek z_gzseek 82# define gzrewind z_gzrewind
81# define gzseek64 z_gzseek64 83# define gzseek z_gzseek
82# define gzsetparams z_gzsetparams 84# define gzseek64 z_gzseek64
83# define gztell z_gztell 85# define gzsetparams z_gzsetparams
84# define gztell64 z_gztell64 86# define gztell z_gztell
85# define gzungetc z_gzungetc 87# define gztell64 z_gztell64
86# define gzwrite z_gzwrite 88# define gzungetc z_gzungetc
89# define gzwrite z_gzwrite
90# endif
87# define inflate z_inflate 91# define inflate z_inflate
88# define inflateBack z_inflateBack 92# define inflateBack z_inflateBack
89# define inflateBackEnd z_inflateBackEnd 93# define inflateBackEnd z_inflateBackEnd
@@ -104,10 +108,14 @@
104# define inflate_copyright z_inflate_copyright 108# define inflate_copyright z_inflate_copyright
105# define inflate_fast z_inflate_fast 109# define inflate_fast z_inflate_fast
106# define inflate_table z_inflate_table 110# define inflate_table z_inflate_table
107# define uncompress z_uncompress 111# ifndef Z_SOLO
112# define uncompress z_uncompress
113# endif
108# define zError z_zError 114# define zError z_zError
109# define zcalloc z_zcalloc 115# ifndef Z_SOLO
110# define zcfree z_zcfree 116# define zcalloc z_zcalloc
117# define zcfree z_zcfree
118# endif
111# define zlibCompileFlags z_zlibCompileFlags 119# define zlibCompileFlags z_zlibCompileFlags
112# define zlibVersion z_zlibVersion 120# define zlibVersion z_zlibVersion
113 121
@@ -117,9 +125,11 @@
117# define alloc_func z_alloc_func 125# define alloc_func z_alloc_func
118# define charf z_charf 126# define charf z_charf
119# define free_func z_free_func 127# define free_func z_free_func
120# define gzFile z_gzFile 128# ifndef Z_SOLO
121# define gz_header z_gz_header 129# define gzFile z_gzFile
122# define gz_headerp z_gz_headerp 130# define gz_header z_gz_header
131# define gz_headerp z_gz_headerp
132# endif
123# define in_func z_in_func 133# define in_func z_in_func
124# define intf z_intf 134# define intf z_intf
125# define out_func z_out_func 135# define out_func z_out_func
@@ -132,7 +142,9 @@
132# define voidpf z_voidpf 142# define voidpf z_voidpf
133 143
134/* all zlib structs in zlib.h and zconf.h */ 144/* all zlib structs in zlib.h and zconf.h */
135# define gz_header_s z_gz_header_s 145# ifndef Z_SOLO
146# define gz_header_s z_gz_header_s
147# endif
136# define internal_state z_internal_state 148# define internal_state z_internal_state
137 149
138#endif 150#endif
@@ -379,7 +391,9 @@ typedef uLong FAR uLongf;
379#endif 391#endif
380 392
381#ifdef STDC 393#ifdef STDC
382# include <sys/types.h> /* for off_t */ 394# ifndef Z_SOLO
395# include <sys/types.h> /* for off_t */
396# endif
383#endif 397#endif
384 398
385/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and 399/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
@@ -396,7 +410,7 @@ typedef uLong FAR uLongf;
396# define Z_LARGE 410# define Z_LARGE
397#endif 411#endif
398 412
399#if defined(Z_HAVE_UNISTD_H) || defined(Z_LARGE) 413#if (defined(Z_HAVE_UNISTD_H) || defined(Z_LARGE)) && !defined(Z_SOLO)
400# include <unistd.h> /* for SEEK_* and off_t */ 414# include <unistd.h> /* for SEEK_* and off_t */
401# ifdef VMS 415# ifdef VMS
402# include <unixio.h> /* for off_t */ 416# include <unixio.h> /* for off_t */
@@ -406,7 +420,7 @@ typedef uLong FAR uLongf;
406# endif 420# endif
407#endif 421#endif
408 422
409#ifndef SEEK_SET 423#if !defined(SEEK_SET) && !defined(Z_SOLO)
410# define SEEK_SET 0 /* Seek from beginning of file. */ 424# define SEEK_SET 0 /* Seek from beginning of file. */
411# define SEEK_CUR 1 /* Seek from current position. */ 425# define SEEK_CUR 1 /* Seek from current position. */
412# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ 426# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
diff --git a/zconf.h.in b/zconf.h.in
index bcb7615..ed16b06 100644
--- a/zconf.h.in
+++ b/zconf.h.in
@@ -28,9 +28,11 @@
28# define adler32 z_adler32 28# define adler32 z_adler32
29# define adler32_combine z_adler32_combine 29# define adler32_combine z_adler32_combine
30# define adler32_combine64 z_adler32_combine64 30# define adler32_combine64 z_adler32_combine64
31# define compress z_compress 31# ifndef Z_SOLO
32# define compress2 z_compress2 32# define compress z_compress
33# define compressBound z_compressBound 33# define compress2 z_compress2
34# define compressBound z_compressBound
35# endif
34# define crc32 z_crc32 36# define crc32 z_crc32
35# define crc32_combine z_crc32_combine 37# define crc32_combine z_crc32_combine
36# define crc32_combine64 z_crc32_combine64 38# define crc32_combine64 z_crc32_combine64
@@ -49,39 +51,41 @@
49# define deflateTune z_deflateTune 51# define deflateTune z_deflateTune
50# define deflate_copyright z_deflate_copyright 52# define deflate_copyright z_deflate_copyright
51# define get_crc_table z_get_crc_table 53# define get_crc_table z_get_crc_table
52# define gz_error z_gz_error 54# ifndef Z_SOLO
53# define gz_intmax z_gz_intmax 55# define gz_error z_gz_error
54# define gz_strwinerror z_gz_strwinerror 56# define gz_intmax z_gz_intmax
55# define gzbuffer z_gzbuffer 57# define gz_strwinerror z_gz_strwinerror
56# define gzclearerr z_gzclearerr 58# define gzbuffer z_gzbuffer
57# define gzclose z_gzclose 59# define gzclearerr z_gzclearerr
58# define gzclose_r z_gzclose_r 60# define gzclose z_gzclose
59# define gzclose_w z_gzclose_w 61# define gzclose_r z_gzclose_r
60# define gzdirect z_gzdirect 62# define gzclose_w z_gzclose_w
61# define gzdopen z_gzdopen 63# define gzdirect z_gzdirect
62# define gzeof z_gzeof 64# define gzdopen z_gzdopen
63# define gzerror z_gzerror 65# define gzeof z_gzeof
64# define gzflags z_gzflags 66# define gzerror z_gzerror
65# define gzflush z_gzflush 67# define gzflags z_gzflags
66# define gzgetc z_gzgetc 68# define gzflush z_gzflush
67# define gzgetc_ z_gzgetc_ 69# define gzgetc z_gzgetc
68# define gzgets z_gzgets 70# define gzgetc_ z_gzgetc_
69# define gzoffset z_gzoffset 71# define gzgets z_gzgets
70# define gzoffset64 z_gzoffset64 72# define gzoffset z_gzoffset
71# define gzopen z_gzopen 73# define gzoffset64 z_gzoffset64
72# define gzopen64 z_gzopen64 74# define gzopen z_gzopen
73# define gzprintf z_gzprintf 75# define gzopen64 z_gzopen64
74# define gzputc z_gzputc 76# define gzprintf z_gzprintf
75# define gzputs z_gzputs 77# define gzputc z_gzputc
76# define gzread z_gzread 78# define gzputs z_gzputs
77# define gzrewind z_gzrewind 79# define gzread z_gzread
78# define gzseek z_gzseek 80# define gzrewind z_gzrewind
79# define gzseek64 z_gzseek64 81# define gzseek z_gzseek
80# define gzsetparams z_gzsetparams 82# define gzseek64 z_gzseek64
81# define gztell z_gztell 83# define gzsetparams z_gzsetparams
82# define gztell64 z_gztell64 84# define gztell z_gztell
83# define gzungetc z_gzungetc 85# define gztell64 z_gztell64
84# define gzwrite z_gzwrite 86# define gzungetc z_gzungetc
87# define gzwrite z_gzwrite
88# endif
85# define inflate z_inflate 89# define inflate z_inflate
86# define inflateBack z_inflateBack 90# define inflateBack z_inflateBack
87# define inflateBackEnd z_inflateBackEnd 91# define inflateBackEnd z_inflateBackEnd
@@ -102,10 +106,14 @@
102# define inflate_copyright z_inflate_copyright 106# define inflate_copyright z_inflate_copyright
103# define inflate_fast z_inflate_fast 107# define inflate_fast z_inflate_fast
104# define inflate_table z_inflate_table 108# define inflate_table z_inflate_table
105# define uncompress z_uncompress 109# ifndef Z_SOLO
110# define uncompress z_uncompress
111# endif
106# define zError z_zError 112# define zError z_zError
107# define zcalloc z_zcalloc 113# ifndef Z_SOLO
108# define zcfree z_zcfree 114# define zcalloc z_zcalloc
115# define zcfree z_zcfree
116# endif
109# define zlibCompileFlags z_zlibCompileFlags 117# define zlibCompileFlags z_zlibCompileFlags
110# define zlibVersion z_zlibVersion 118# define zlibVersion z_zlibVersion
111 119
@@ -115,9 +123,11 @@
115# define alloc_func z_alloc_func 123# define alloc_func z_alloc_func
116# define charf z_charf 124# define charf z_charf
117# define free_func z_free_func 125# define free_func z_free_func
118# define gzFile z_gzFile 126# ifndef Z_SOLO
119# define gz_header z_gz_header 127# define gzFile z_gzFile
120# define gz_headerp z_gz_headerp 128# define gz_header z_gz_header
129# define gz_headerp z_gz_headerp
130# endif
121# define in_func z_in_func 131# define in_func z_in_func
122# define intf z_intf 132# define intf z_intf
123# define out_func z_out_func 133# define out_func z_out_func
@@ -130,7 +140,9 @@
130# define voidpf z_voidpf 140# define voidpf z_voidpf
131 141
132/* all zlib structs in zlib.h and zconf.h */ 142/* all zlib structs in zlib.h and zconf.h */
133# define gz_header_s z_gz_header_s 143# ifndef Z_SOLO
144# define gz_header_s z_gz_header_s
145# endif
134# define internal_state z_internal_state 146# define internal_state z_internal_state
135 147
136#endif 148#endif
@@ -377,7 +389,9 @@ typedef uLong FAR uLongf;
377#endif 389#endif
378 390
379#ifdef STDC 391#ifdef STDC
380# include <sys/types.h> /* for off_t */ 392# ifndef Z_SOLO
393# include <sys/types.h> /* for off_t */
394# endif
381#endif 395#endif
382 396
383/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and 397/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
@@ -394,7 +408,7 @@ typedef uLong FAR uLongf;
394# define Z_LARGE 408# define Z_LARGE
395#endif 409#endif
396 410
397#if defined(Z_HAVE_UNISTD_H) || defined(Z_LARGE) 411#if (defined(Z_HAVE_UNISTD_H) || defined(Z_LARGE)) && !defined(Z_SOLO)
398# include <unistd.h> /* for SEEK_* and off_t */ 412# include <unistd.h> /* for SEEK_* and off_t */
399# ifdef VMS 413# ifdef VMS
400# include <unixio.h> /* for off_t */ 414# include <unixio.h> /* for off_t */
@@ -404,7 +418,7 @@ typedef uLong FAR uLongf;
404# endif 418# endif
405#endif 419#endif
406 420
407#ifndef SEEK_SET 421#if !defined(SEEK_SET) && !defined(Z_SOLO)
408# define SEEK_SET 0 /* Seek from beginning of file. */ 422# define SEEK_SET 0 /* Seek from beginning of file. */
409# define SEEK_CUR 1 /* Seek from current position. */ 423# define SEEK_CUR 1 /* Seek from current position. */
410# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ 424# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
diff --git a/zlib.h b/zlib.h
index f77b596..96c2c14 100644
--- a/zlib.h
+++ b/zlib.h
@@ -1112,6 +1112,7 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
1112 27-31: 0 (reserved) 1112 27-31: 0 (reserved)
1113 */ 1113 */
1114 1114
1115#ifndef Z_SOLO
1115 1116
1116 /* utility functions */ 1117 /* utility functions */
1117 1118
@@ -1176,7 +1177,6 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
1176 buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. 1177 buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete.
1177*/ 1178*/
1178 1179
1179
1180 /* gzip file access functions */ 1180 /* gzip file access functions */
1181 1181
1182/* 1182/*
@@ -1501,6 +1501,7 @@ ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
1501 file that is being written concurrently. 1501 file that is being written concurrently.
1502*/ 1502*/
1503 1503
1504#endif /* !Z_SOLO */
1504 1505
1505 /* checksum functions */ 1506 /* checksum functions */
1506 1507
@@ -1603,6 +1604,8 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
1603 inflateBackInit_((strm), (windowBits), (window), \ 1604 inflateBackInit_((strm), (windowBits), (window), \
1604 ZLIB_VERSION, (int)sizeof(z_stream)) 1605 ZLIB_VERSION, (int)sizeof(z_stream))
1605 1606
1607#ifndef Z_SOLO
1608
1606/* gzgetc() macro and its supporting function and exposed data structure. Note 1609/* gzgetc() macro and its supporting function and exposed data structure. Note
1607 * that the real internal state is much larger than the exposed structure. 1610 * that the real internal state is much larger than the exposed structure.
1608 * This abbreviated structure exposes just enough for the gzgetc() macro. The 1611 * This abbreviated structure exposes just enough for the gzgetc() macro. The
@@ -1667,6 +1670,13 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file));
1667 ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); 1670 ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
1668#endif 1671#endif
1669 1672
1673#else /* Z_SOLO */
1674
1675 ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
1676 ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
1677
1678#endif /* !Z_SOLO */
1679
1670/* hack for buggy compilers */ 1680/* hack for buggy compilers */
1671#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL) 1681#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
1672 struct internal_state {int dummy;}; 1682 struct internal_state {int dummy;};
@@ -1677,7 +1687,9 @@ ZEXTERN const char * ZEXPORT zError OF((int));
1677ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp)); 1687ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp));
1678ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)); 1688ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
1679ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int)); 1689ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int));
1680ZEXTERN unsigned long ZEXPORT gzflags OF((void)); 1690#ifndef Z_SOLO
1691 ZEXTERN unsigned long ZEXPORT gzflags OF((void));
1692#endif
1681 1693
1682#ifdef __cplusplus 1694#ifdef __cplusplus
1683} 1695}
diff --git a/zutil.c b/zutil.c
index 8f697cc..8a1d242 100644
--- a/zutil.c
+++ b/zutil.c
@@ -85,7 +85,11 @@ uLong ZEXPORT zlibCompileFlags()
85#ifdef FASTEST 85#ifdef FASTEST
86 flags += 1L << 21; 86 flags += 1L << 21;
87#endif 87#endif
88#ifdef Z_SOLO
89 return flags;
90#else
88 return flags + gzflags(); 91 return flags + gzflags();
92#endif
89} 93}
90 94
91#ifdef DEBUG 95#ifdef DEBUG
@@ -157,6 +161,7 @@ void ZLIB_INTERNAL zmemzero(dest, len)
157} 161}
158#endif 162#endif
159 163
164#ifndef Z_SOLO
160 165
161#ifdef SYS16BIT 166#ifdef SYS16BIT
162 167
@@ -292,3 +297,5 @@ void ZLIB_INTERNAL zcfree (opaque, ptr)
292} 297}
293 298
294#endif /* MY_ZCALLOC */ 299#endif /* MY_ZCALLOC */
300
301#endif /* !Z_SOLO */
diff --git a/zutil.h b/zutil.h
index 86d64bc..634ce34 100644
--- a/zutil.h
+++ b/zutil.h
@@ -21,7 +21,7 @@
21 21
22#include "zlib.h" 22#include "zlib.h"
23 23
24#ifdef STDC 24#if defined(STDC) && !defined(Z_SOLO)
25# if !(defined(_WIN32_WCE) && defined(_MSC_VER)) 25# if !(defined(_WIN32_WCE) && defined(_MSC_VER))
26# include <stddef.h> 26# include <stddef.h>
27# endif 27# endif
@@ -29,6 +29,10 @@
29# include <stdlib.h> 29# include <stdlib.h>
30#endif 30#endif
31 31
32#ifdef Z_SOLO
33 typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */
34#endif
35
32#ifndef local 36#ifndef local
33# define local static 37# define local static
34#endif 38#endif
@@ -78,16 +82,18 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
78 82
79#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) 83#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
80# define OS_CODE 0x00 84# define OS_CODE 0x00
81# if defined(__TURBOC__) || defined(__BORLANDC__) 85# ifndef Z_SOLO
82# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) 86# if defined(__TURBOC__) || defined(__BORLANDC__)
83 /* Allow compilation with ANSI keywords only enabled */ 87# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
84 void _Cdecl farfree( void *block ); 88 /* Allow compilation with ANSI keywords only enabled */
85 void *_Cdecl farmalloc( unsigned long nbytes ); 89 void _Cdecl farfree( void *block );
86# else 90 void *_Cdecl farmalloc( unsigned long nbytes );
87# include <alloc.h> 91# else
92# include <alloc.h>
93# endif
94# else /* MSC or DJGPP */
95# include <malloc.h>
88# endif 96# endif
89# else /* MSC or DJGPP */
90# include <malloc.h>
91# endif 97# endif
92#endif 98#endif
93 99
@@ -107,18 +113,20 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
107 113
108#ifdef OS2 114#ifdef OS2
109# define OS_CODE 0x06 115# define OS_CODE 0x06
110# ifdef M_I86 116# if defined(M_I86) && !defined(Z_SOLO)
111# include <malloc.h> 117# include <malloc.h>
112# endif 118# endif
113#endif 119#endif
114 120
115#if defined(MACOS) || defined(TARGET_OS_MAC) 121#if defined(MACOS) || defined(TARGET_OS_MAC)
116# define OS_CODE 0x07 122# define OS_CODE 0x07
117# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os 123# ifndef Z_SOLO
118# include <unix.h> /* for fdopen */ 124# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
119# else 125# include <unix.h> /* for fdopen */
120# ifndef fdopen 126# else
121# define fdopen(fd,mode) NULL /* No fdopen() */ 127# ifndef fdopen
128# define fdopen(fd,mode) NULL /* No fdopen() */
129# endif
122# endif 130# endif
123# endif 131# endif
124#endif 132#endif
@@ -177,7 +185,7 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
177 185
178 /* functions */ 186 /* functions */
179 187
180#if defined(pyr) 188#if defined(pyr) || defined(Z_SOLO)
181# define NO_MEMCPY 189# define NO_MEMCPY
182#endif 190#endif
183#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) 191#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
@@ -226,10 +234,11 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
226# define Tracecv(c,x) 234# define Tracecv(c,x)
227#endif 235#endif
228 236
229 237#ifndef Z_SOLO
230voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, 238 voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
231 unsigned size)); 239 unsigned size));
232void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); 240 void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr));
241#endif
233 242
234#define ZALLOC(strm, items, size) \ 243#define ZALLOC(strm, items, size) \
235 (*((strm)->zalloc))((strm)->opaque, (items), (size)) 244 (*((strm)->zalloc))((strm)->opaque, (items), (size))