1
diff -ac zlib113/deflate.c zlibwce/deflate.c
2
*** zlib113/deflate.c Fri Jul 10 01:06:12 1998
3
--- zlibwce/deflate.c Thu May 25 16:42:18 2000
11
+ /* Windows CE is not support DEBUG version's zlib */
12
+ # define check_match(s, start, match, length)
14
/* ===========================================================================
15
* Check that the match at match_start is indeed a match.
20
do { putc(s->window[start++], stderr); } while (--length != 0);
25
# define check_match(s, start, match, length)
27
diff -ac zlib113/trees.c zlibwce/trees.c
28
*** zlib113/trees.c Thu Jul 09 01:32:58 1998
29
--- zlibwce/trees.c Thu May 25 16:42:50 2000
33
/* Send a code of the given tree. c and tree must not have side effects */
37
+ /* Windows CE is not support DEBUG version's zlib */
38
+ # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
41
# define send_code(s, c, tree) \
42
{ if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
43
send_bits(s, tree[c].Code, tree[c].Len); }
47
/* ===========================================================================
48
diff -ac zlib113/zconf.h zlibwce/zconf.h
49
*** zlib113/zconf.h Thu Jul 09 02:55:28 1998
50
--- zlibwce/zconf.h Thu May 25 16:36:16 2000
54
# define NEED_DUMMY_RETURN
57
+ /* Windows CE is not have errno.h file: */
58
+ #if defined(_WIN32_WCE)
63
/* Maximum value for memLevel in deflateInit2 */
68
/* Compile with -DZLIB_DLL for Windows DLL support */
70
! # if defined(_WINDOWS) || defined(WINDOWS)
76
/* Compile with -DZLIB_DLL for Windows DLL support */
78
! # if defined(_WINDOWS) || defined(WINDOWS) || defined(_WIN32_WCE)
82
diff -ac zlib113/zutil.c zlibwce/zutil.c
83
*** zlib113/zutil.c Thu Jul 09 02:01:48 1998
84
--- zlibwce/zutil.c Thu May 25 16:43:34 2000
92
+ /* Windows CE is not support DEBUG version's zlib */
105
/* exported to allow conversion of error code to string for compress() and
112
if (opaque) items += size - size; /* make compiler happy */
114
+ return (voidpf)malloc(items * size);
116
return (voidpf)calloc(items, size);
120
void zcfree (opaque, ptr)
121
diff -ac zlib113/zutil.h zlibwce/zutil.h
122
*** zlib113/zutil.h Thu Jul 09 02:01:48 1998
123
--- zlibwce/zutil.h Thu May 25 16:41:44 2000
131
+ # include <malloc.h>
142
/* Diagnostic functions */
145
+ /* Windows CE is not support DEBUG version's zlib */
146
+ # define Assert(cond,msg)
149
+ # define Tracevv(x)
150
+ # define Tracec(c,x)
151
+ # define Tracecv(c,x)
154
extern int z_verbose;
155
extern void z_error OF((char *m));
159
# define Tracevv(x) {if (z_verbose>1) fprintf x ;}
160
# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
161
# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
164
# define Assert(cond,msg)
166
*** zlib113/gzio.c Sat Jul 8 13:59:49 2000
167
--- zlibwce/gzio.c Sat Jul 8 13:58:29 2000
170
! /* gzio.c -- IO on .gz files
171
* Copyright (C) 1995-1998 Jean-loup Gailly.
172
* For conditions of distribution and use, see copyright notice in zlib.h
174
* Compile this file with -DNO_DEFLATE to avoid the compression code.
176
! /* gzio.c -- IO on .gz files for WindowsCE
177
* Copyright (C) 1995-1998 Jean-loup Gailly.
178
+ * Copyright (C) 2000 Tenik Co.,Ltd.
179
* For conditions of distribution and use, see copyright notice in zlib.h
181
* Compile this file with -DNO_DEFLATE to avoid the compression code.
185
/* @(#) $Id: zlib.diff,v 1.1.1.1 2000/11/17 14:22:46 rocco Exp $ */
193
/* @(#) $Id: zlib.diff,v 1.1.1.1 2000/11/17 14:22:46 rocco Exp $ */
195
! #include <windows.h>
202
int z_err; /* error code for last stream operation */
203
int z_eof; /* set if end of input file */
204
! FILE *file; /* .gz file */
205
Byte *inbuf; /* input buffer */
206
Byte *outbuf; /* output buffer */
207
uLong crc; /* crc32 of uncompressed data */
210
int z_err; /* error code for last stream operation */
211
int z_eof; /* set if end of input file */
212
! HANDLE file; /* .gz file */
213
Byte *inbuf; /* input buffer */
214
Byte *outbuf; /* output buffer */
215
uLong crc; /* crc32 of uncompressed data */
218
local int get_byte OF((gz_stream *s));
219
local void check_header OF((gz_stream *s));
220
local int destroy OF((gz_stream *s));
221
! local void putLong OF((FILE *file, uLong x));
222
local uLong getLong OF((gz_stream *s));
224
/* ===========================================================================
226
local int get_byte OF((gz_stream *s));
227
local void check_header OF((gz_stream *s));
228
local int destroy OF((gz_stream *s));
229
! local void putLong OF((HANDLE file, uLong x));
230
local uLong getLong OF((gz_stream *s));
232
/* ===========================================================================
237
char fmode[80]; /* copy of mode, without the compression level */
241
+ TCHAR file[MAX_PATH];
243
if (!path || !mode) return Z_NULL;
247
s->stream.next_in = s->inbuf = Z_NULL;
248
s->stream.next_out = s->outbuf = Z_NULL;
249
s->stream.avail_in = s->stream.avail_out = 0;
253
s->crc = crc32(0L, Z_NULL, 0);
255
s->stream.next_in = s->inbuf = Z_NULL;
256
s->stream.next_out = s->outbuf = Z_NULL;
257
s->stream.avail_in = s->stream.avail_out = 0;
258
! s->file = INVALID_HANDLE_VALUE;
261
s->crc = crc32(0L, Z_NULL, 0);
264
if (*p == 'r') s->mode = 'r';
265
if (*p == 'w' || *p == 'a') s->mode = 'w';
266
if (*p >= '0' && *p <= '9') {
268
! } else if (*p == 'f') {
269
! strategy = Z_FILTERED;
270
! } else if (*p == 'h') {
271
! strategy = Z_HUFFMAN_ONLY;
273
! *m++ = *p; /* copy the mode */
275
} while (*p++ && m != fmode + sizeof(fmode));
276
if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL;
279
if (*p == 'r') s->mode = 'r';
280
if (*p == 'w' || *p == 'a') s->mode = 'w';
281
if (*p >= '0' && *p <= '9') {
283
! } else if (*p == 'f') {
284
! strategy = Z_FILTERED;
285
! } else if (*p == 'h') {
286
! strategy = Z_HUFFMAN_ONLY;
288
! *m++ = *p; /* copy the mode */
290
} while (*p++ && m != fmode + sizeof(fmode));
291
if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL;
296
s->stream.avail_out = Z_BUFSIZE;
299
! s->file = fd < 0 ? F_OPEN(path, fmode) : (FILE*)fdopen(fd, fmode);
301
! if (s->file == NULL) {
302
return destroy(s), (gzFile)Z_NULL;
304
if (s->mode == 'w') {
305
/* Write a very simple .gz header:
307
! fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1],
308
! Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE);
310
! /* We use 10L instead of ftell(s->file) to because ftell causes an
311
* fflush on some systems. This version of the library doesn't use
312
* startpos anyway in write mode, so this initialization is not
316
! check_header(s); /* skip the .gz header */
317
! s->startpos = (ftell(s->file) - s->stream.avail_in);
323
s->stream.avail_out = Z_BUFSIZE;
325
! SetLastError(NO_ERROR);
326
! if ((HANDLE)fd == INVALID_HANDLE_VALUE) {
327
! MultiByteToWideChar(CP_ACP, 0, path, -1, file, MAX_PATH);
328
! s->file = CreateFile(file, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, 0, NULL);
330
! s->file = (HANDLE)fd;
333
! if (s->file == INVALID_HANDLE_VALUE) {
334
return destroy(s), (gzFile)Z_NULL;
336
if (s->mode == 'w') {
337
/* Write a very simple .gz header:
339
! cbuff[0] = gz_magic[0];
340
! cbuff[1] = gz_magic[1];
341
! cbuff[2] = Z_DEFLATED;
342
! cbuff[3] = 0; /*flags*/
346
! cbuff[7] = 0; /*time*/;
347
! cbuff[8] = 0; /*xflags*/;
348
! cbuff[9] = OS_CODE;
349
! WriteFile(s->file, cbuff, 10, &size, NULL);
351
! /* We use 10L instead of ftell(s->file) to because ftell causes an
352
* fflush on some systems. This version of the library doesn't use
353
* startpos anyway in write mode, so this initialization is not
357
! check_header(s); /* skip the .gz header */
358
! s->startpos = (SetFilePointer(s->file, 0, NULL, FILE_CURRENT) - s->stream.avail_in);
367
! if (fd < 0) return (gzFile)Z_NULL;
368
! sprintf(name, "<fd:%d>", fd); /* for debugging */
370
return gz_open (name, mode, fd);
377
! if ((HANDLE)fd == INVALID_HANDLE_VALUE)
378
! return (gzFile)Z_NULL;
380
+ strcpy(name, "<gzdopen>"); /* for debugging */
382
return gz_open (name, mode, fd);
390
gz_stream *s = (gz_stream*)file;
393
if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
397
/* Make room to allow flushing */
398
if (s->stream.avail_out == 0) {
400
! s->stream.next_out = s->outbuf;
401
! if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) {
402
! s->z_err = Z_ERRNO;
404
! s->stream.avail_out = Z_BUFSIZE;
407
return deflateParams (&(s->stream), level, strategy);
409
/* Make room to allow flushing */
410
if (s->stream.avail_out == 0) {
412
! s->stream.next_out = s->outbuf;
413
! if (!WriteFile(s->file, s->outbuf, Z_BUFSIZE, &size, NULL) || size != Z_BUFSIZE) {
414
! s->z_err = Z_ERRNO;
416
! s->stream.avail_out = Z_BUFSIZE;
419
return deflateParams (&(s->stream), level, strategy);
422
local int get_byte(s)
425
! if (s->z_eof) return EOF;
426
if (s->stream.avail_in == 0) {
428
! s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file);
429
! if (s->stream.avail_in == 0) {
431
! if (ferror(s->file)) s->z_err = Z_ERRNO;
434
! s->stream.next_in = s->inbuf;
436
s->stream.avail_in--;
437
return *(s->stream.next_in)++;
439
local int get_byte(s)
442
! if (s->z_eof) return -1;
443
if (s->stream.avail_in == 0) {
444
! SetLastError(NO_ERROR);
445
! if (!ReadFile(s->file, s->inbuf, Z_BUFSIZE, &s->stream.avail_in, NULL)) {
446
! s->z_err = Z_ERRNO;
448
! if (s->stream.avail_in == 0) {
452
! s->stream.next_in = s->inbuf;
454
s->stream.avail_in--;
455
return *(s->stream.next_in)++;
459
/* Check the gzip magic header */
460
for (len = 0; len < 2; len++) {
462
! if (c != gz_magic[len]) {
463
! if (len != 0) s->stream.avail_in++, s->stream.next_in--;
465
! s->stream.avail_in++, s->stream.next_in--;
466
! s->transparent = 1;
468
! s->z_err = s->stream.avail_in != 0 ? Z_OK : Z_STREAM_END;
472
method = get_byte(s);
474
if (method != Z_DEFLATED || (flags & RESERVED) != 0) {
475
! s->z_err = Z_DATA_ERROR;
479
/* Discard time, xflags and OS code: */
482
/* Check the gzip magic header */
483
for (len = 0; len < 2; len++) {
485
! if (c != gz_magic[len]) {
486
! if (len != 0) s->stream.avail_in++, s->stream.next_in--;
488
! s->stream.avail_in++, s->stream.next_in--;
489
! s->transparent = 1;
491
! s->z_err = s->stream.avail_in != 0 ? Z_OK : Z_STREAM_END;
495
method = get_byte(s);
497
if (method != Z_DEFLATED || (flags & RESERVED) != 0) {
498
! s->z_err = Z_DATA_ERROR;
502
/* Discard time, xflags and OS code: */
505
for (len = 0; len < 6; len++) (void)get_byte(s);
507
if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */
508
! len = (uInt)get_byte(s);
509
! len += ((uInt)get_byte(s))<<8;
510
! /* len is garbage if EOF but the loop below will quit anyway */
511
! while (len-- != 0 && get_byte(s) != EOF) ;
513
if ((flags & ORIG_NAME) != 0) { /* skip the original file name */
514
! while ((c = get_byte(s)) != 0 && c != EOF) ;
516
if ((flags & COMMENT) != 0) { /* skip the .gz file comment */
517
! while ((c = get_byte(s)) != 0 && c != EOF) ;
519
if ((flags & HEAD_CRC) != 0) { /* skip the header crc */
520
! for (len = 0; len < 2; len++) (void)get_byte(s);
522
s->z_err = s->z_eof ? Z_DATA_ERROR : Z_OK;
525
for (len = 0; len < 6; len++) (void)get_byte(s);
527
if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */
528
! len = (uInt)get_byte(s);
529
! len += ((uInt)get_byte(s))<<8;
530
! /* len is garbage if EOF but the loop below will quit anyway */
531
! while (len-- != 0 && get_byte(s) != -1) ;
533
if ((flags & ORIG_NAME) != 0) { /* skip the original file name */
534
! while ((c = get_byte(s)) != 0 && c != -1) ;
536
if ((flags & COMMENT) != 0) { /* skip the .gz file comment */
537
! while ((c = get_byte(s)) != 0 && c != -1) ;
539
if ((flags & HEAD_CRC) != 0) { /* skip the header crc */
540
! for (len = 0; len < 2; len++) (void)get_byte(s);
542
s->z_err = s->z_eof ? Z_DATA_ERROR : Z_OK;
548
if (s->stream.state != NULL) {
549
! if (s->mode == 'w') {
551
! err = Z_STREAM_ERROR;
553
! err = deflateEnd(&(s->stream));
555
! } else if (s->mode == 'r') {
556
! err = inflateEnd(&(s->stream));
559
! if (s->file != NULL && fclose(s->file)) {
561
! if (errno != ESPIPE) /* fclose is broken for pipes in HP/UX */
565
if (s->z_err < 0) err = s->z_err;
570
if (s->stream.state != NULL) {
571
! if (s->mode == 'w') {
573
! err = Z_STREAM_ERROR;
575
! err = deflateEnd(&(s->stream));
577
! } else if (s->mode == 'r') {
578
! err = inflateEnd(&(s->stream));
581
! if (s->file != NULL && !CloseHandle(s->file)) {
584
if (s->z_err < 0) err = s->z_err;
589
gz_stream *s = (gz_stream*)file;
590
Bytef *start = (Bytef*)buf; /* starting point for crc computation */
591
Byte *next_out; /* == stream.next_out but not forced far (for MSDOS) */
594
if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR;
599
while (s->stream.avail_out != 0) {
601
! if (s->transparent) {
602
! /* Copy first the lookahead bytes: */
603
! uInt n = s->stream.avail_in;
604
! if (n > s->stream.avail_out) n = s->stream.avail_out;
606
! zmemcpy(s->stream.next_out, s->stream.next_in, n);
608
! s->stream.next_out = next_out;
609
! s->stream.next_in += n;
610
! s->stream.avail_out -= n;
611
! s->stream.avail_in -= n;
613
! if (s->stream.avail_out > 0) {
614
! s->stream.avail_out -= fread(next_out, 1, s->stream.avail_out,
617
! len -= s->stream.avail_out;
618
! s->stream.total_in += (uLong)len;
619
! s->stream.total_out += (uLong)len;
620
if (len == 0) s->z_eof = 1;
623
if (s->stream.avail_in == 0 && !s->z_eof) {
626
! s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file);
627
if (s->stream.avail_in == 0) {
629
- if (ferror(s->file)) {
630
- s->z_err = Z_ERRNO;
634
s->stream.next_in = s->inbuf;
636
s->z_err = inflate(&(s->stream), Z_NO_FLUSH);
638
! if (s->z_err == Z_STREAM_END) {
639
! /* Check CRC and original size */
640
! s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
641
! start = s->stream.next_out;
643
! if (getLong(s) != s->crc) {
644
! s->z_err = Z_DATA_ERROR;
647
/* The uncompressed length returned by above getlong() may
648
* be different from s->stream.total_out) in case of
649
! * concatenated .gz files. Check for such files:
652
! if (s->z_err == Z_OK) {
653
! uLong total_in = s->stream.total_in;
654
! uLong total_out = s->stream.total_out;
656
! inflateReset(&(s->stream));
657
! s->stream.total_in = total_in;
658
! s->stream.total_out = total_out;
659
! s->crc = crc32(0L, Z_NULL, 0);
663
! if (s->z_err != Z_OK || s->z_eof) break;
665
s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
669
while (s->stream.avail_out != 0) {
671
! if (s->transparent) {
672
! /* Copy first the lookahead bytes: */
673
! uInt n = s->stream.avail_in;
674
! if (n > s->stream.avail_out) n = s->stream.avail_out;
676
! zmemcpy(s->stream.next_out, s->stream.next_in, n);
678
! s->stream.next_out = next_out;
679
! s->stream.next_in += n;
680
! s->stream.avail_out -= n;
681
! s->stream.avail_in -= n;
683
! if (s->stream.avail_out > 0) {
684
! if (ReadFile(s->file, next_out, s->stream.avail_out, &size, NULL)) {
685
! s->stream.avail_out -= size;
688
! len -= s->stream.avail_out;
689
! s->stream.total_in += (uLong)len;
690
! s->stream.total_out += (uLong)len;
691
if (len == 0) s->z_eof = 1;
694
if (s->stream.avail_in == 0 && !s->z_eof) {
696
! SetLastError(NO_ERROR);
697
! if (!ReadFile(s->file, s->inbuf, Z_BUFSIZE, &s->stream.avail_in, NULL)) {
699
! s->z_err = Z_ERRNO;
702
if (s->stream.avail_in == 0) {
705
s->stream.next_in = s->inbuf;
707
s->z_err = inflate(&(s->stream), Z_NO_FLUSH);
709
! if (s->z_err == Z_STREAM_END) {
710
! /* Check CRC and original size */
711
! s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
712
! start = s->stream.next_out;
714
! if (getLong(s) != s->crc) {
715
! s->z_err = Z_DATA_ERROR;
718
/* The uncompressed length returned by above getlong() may
719
* be different from s->stream.total_out) in case of
720
! * concatenated .gz files. Check for such files:
723
! if (s->z_err == Z_OK) {
724
! uLong total_in = s->stream.total_in;
725
! uLong total_out = s->stream.total_out;
727
! inflateReset(&(s->stream));
728
! s->stream.total_in = total_in;
729
! s->stream.total_out = total_out;
730
! s->crc = crc32(0L, Z_NULL, 0);
734
! if (s->z_err != Z_OK || s->z_eof) break;
736
s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
743
gz_stream *s = (gz_stream*)file;
746
if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
750
if (s->stream.avail_out == 0) {
752
s->stream.next_out = s->outbuf;
753
! if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) {
758
if (s->stream.avail_out == 0) {
760
s->stream.next_out = s->outbuf;
761
! if (!WriteFile(s->file, s->outbuf, Z_BUFSIZE, &size, NULL) || size != Z_BUFSIZE) {
767
char buf[Z_PRINTF_BUFSIZE];
771
va_start(va, format);
772
! #ifdef HAS_vsnprintf
773
! (void)vsnprintf(buf, sizeof(buf), format, va);
775
! (void)vsprintf(buf, format, va);
778
len = strlen(buf); /* some *sprintf don't return the nb of bytes written */
779
if (len <= 0) return 0;
782
char buf[Z_PRINTF_BUFSIZE];
785
+ TCHAR form[Z_PRINTF_BUFSIZE];
786
+ TCHAR tbuf[Z_PRINTF_BUFSIZE];
789
va_start(va, format);
790
! MultiByteToWideChar(CP_ACP, 0, format, -1, form, Z_PRINTF_BUFSIZE);
791
! len = lstrlen(form);
792
! for ( n = 0; n < len; n++ ) {
793
! if ( TEXT('%') == form[n] ) {
795
! if ( TEXT('c') == form[n] ) {
796
! form[n] = TEXT('C');
797
! } else if ( TEXT('s') == form[n] ) {
798
! form[n] = TEXT('S');
802
! (void)vswprintf(tbuf, form, va);
804
+ WideCharToMultiByte(CP_ACP, 0, tbuf, -1, buf, Z_PRINTF_BUFSIZE, NULL, NULL);
805
len = strlen(buf); /* some *sprintf don't return the nb of bytes written */
806
if (len <= 0) return 0;
810
#else /* not ANSI C */
812
int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
813
! a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
816
int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
817
! a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
819
char buf[Z_PRINTF_BUFSIZE];
822
#else /* not ANSI C */
824
int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
825
! a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
828
int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
829
! a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
831
char buf[Z_PRINTF_BUFSIZE];
837
snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8,
838
! a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
840
sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8,
841
! a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
843
len = strlen(buf); /* old sprintf doesn't return the nb of bytes written */
844
if (len <= 0) return 0;
848
snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8,
849
! a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
851
sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8,
852
! a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
854
len = strlen(buf); /* old sprintf doesn't return the nb of bytes written */
855
if (len <= 0) return 0;
861
gz_stream *s = (gz_stream*)file;
864
if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
868
len = Z_BUFSIZE - s->stream.avail_out;
871
! if ((uInt)fwrite(s->outbuf, 1, len, s->file) != len) {
876
len = Z_BUFSIZE - s->stream.avail_out;
879
! if (!WriteFile(s->file, s->outbuf, len, &size, NULL) || (uInt)size != len) {
886
s->z_err = deflate(&(s->stream), flush);
888
! /* Ignore the second of two consecutive flushes: */
889
! if (len == 0 && s->z_err == Z_BUF_ERROR) s->z_err = Z_OK;
891
/* deflate has finished flushing only when it hasn't used up
892
* all the available space in the output buffer:
895
s->z_err = deflate(&(s->stream), flush);
897
! /* Ignore the second of two consecutive flushes: */
898
! if (len == 0 && s->z_err == Z_BUF_ERROR) s->z_err = Z_OK;
900
/* deflate has finished flushing only when it hasn't used up
901
* all the available space in the output buffer:
904
int err = do_flush (file, flush);
908
return s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
910
#endif /* NO_DEFLATE */
912
int err = do_flush (file, flush);
916
return s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
918
#endif /* NO_DEFLATE */
921
gz_stream *s = (gz_stream*)file;
923
if (s == NULL || whence == SEEK_END ||
924
! s->z_err == Z_ERRNO || s->z_err == Z_DATA_ERROR) {
928
if (s->mode == 'w') {
932
! if (whence == SEEK_SET) {
933
! offset -= s->stream.total_in;
935
! if (offset < 0) return -1L;
937
! /* At this point, offset is the number of zero bytes to write. */
938
! if (s->inbuf == Z_NULL) {
939
! s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); /* for seeking */
940
! zmemzero(s->inbuf, Z_BUFSIZE);
942
! while (offset > 0) {
943
! uInt size = Z_BUFSIZE;
944
! if (offset < Z_BUFSIZE) size = (uInt)offset;
946
! size = gzwrite(file, s->inbuf, size);
947
! if (size == 0) return -1L;
951
! return (z_off_t)s->stream.total_in;
954
/* Rest of function is for reading only */
956
gz_stream *s = (gz_stream*)file;
958
if (s == NULL || whence == SEEK_END ||
959
! s->z_err == Z_ERRNO || s->z_err == Z_DATA_ERROR) {
963
if (s->mode == 'w') {
967
! if (whence == SEEK_SET) {
968
! offset -= s->stream.total_in;
970
! if (offset < 0) return -1L;
972
! /* At this point, offset is the number of zero bytes to write. */
973
! if (s->inbuf == Z_NULL) {
974
! s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); /* for seeking */
975
! zmemzero(s->inbuf, Z_BUFSIZE);
977
! while (offset > 0) {
978
! uInt size = Z_BUFSIZE;
979
! if (offset < Z_BUFSIZE) size = (uInt)offset;
981
! size = gzwrite(file, s->inbuf, size);
982
! if (size == 0) return -1L;
986
! return (z_off_t)s->stream.total_in;
989
/* Rest of function is for reading only */
993
/* compute absolute position */
994
if (whence == SEEK_CUR) {
995
! offset += s->stream.total_out;
997
if (offset < 0) return -1L;
999
if (s->transparent) {
1000
! /* map to fseek */
1001
! s->stream.avail_in = 0;
1002
! s->stream.next_in = s->inbuf;
1003
! if (fseek(s->file, offset, SEEK_SET) < 0) return -1L;
1005
! s->stream.total_in = s->stream.total_out = (uLong)offset;
1009
/* For a negative seek, rewind and use positive seek */
1010
if ((uLong)offset >= s->stream.total_out) {
1011
! offset -= s->stream.total_out;
1012
} else if (gzrewind(file) < 0) {
1015
/* offset is now the number of bytes to skip. */
1017
if (offset != 0 && s->outbuf == Z_NULL) {
1018
! s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
1020
while (offset > 0) {
1021
! int size = Z_BUFSIZE;
1022
! if (offset < Z_BUFSIZE) size = (int)offset;
1024
! size = gzread(file, s->outbuf, (uInt)size);
1025
! if (size <= 0) return -1L;
1028
return (z_off_t)s->stream.total_out;
1032
/* compute absolute position */
1033
if (whence == SEEK_CUR) {
1034
! offset += s->stream.total_out;
1036
if (offset < 0) return -1L;
1038
if (s->transparent) {
1039
! /* map to fseek */
1040
! s->stream.avail_in = 0;
1041
! s->stream.next_in = s->inbuf;
1042
! if (SetFilePointer(s->file, offset, NULL, FILE_BEGIN) == 0xFFFFFFFF) return -1L;
1044
! s->stream.total_in = s->stream.total_out = (uLong)offset;
1048
/* For a negative seek, rewind and use positive seek */
1049
if ((uLong)offset >= s->stream.total_out) {
1050
! offset -= s->stream.total_out;
1051
} else if (gzrewind(file) < 0) {
1054
/* offset is now the number of bytes to skip. */
1056
if (offset != 0 && s->outbuf == Z_NULL) {
1057
! s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
1059
while (offset > 0) {
1060
! int size = Z_BUFSIZE;
1061
! if (offset < Z_BUFSIZE) size = (int)offset;
1063
! size = gzread(file, s->outbuf, (uInt)size);
1064
! if (size <= 0) return -1L;
1067
return (z_off_t)s->stream.total_out;
1073
gz_stream *s = (gz_stream*)file;
1075
if (s == NULL || s->mode != 'r') return -1;
1081
gz_stream *s = (gz_stream*)file;
1083
if (s == NULL || s->mode != 'r') return -1;
1088
s->stream.avail_in = 0;
1089
s->stream.next_in = s->inbuf;
1090
s->crc = crc32(0L, Z_NULL, 0);
1092
if (s->startpos == 0) { /* not a compressed file */
1097
(void) inflateReset(&s->stream);
1098
! return fseek(s->file, s->startpos, SEEK_SET);
1101
/* ===========================================================================
1103
s->stream.avail_in = 0;
1104
s->stream.next_in = s->inbuf;
1105
s->crc = crc32(0L, Z_NULL, 0);
1107
if (s->startpos == 0) { /* not a compressed file */
1108
! SetFilePointer(s->file, 0, NULL, FILE_BEGIN);
1112
(void) inflateReset(&s->stream);
1113
! return SetFilePointer(s->file, s->startpos, NULL, FILE_BEGIN);
1116
/* ===========================================================================
1119
Outputs a long in LSB order to the given file
1121
local void putLong (file, x)
1126
for (n = 0; n < 4; n++) {
1127
! fputc((int)(x & 0xff), file);
1132
Outputs a long in LSB order to the given file
1134
local void putLong (file, x)
1141
for (n = 0; n < 4; n++) {
1142
! ch[0] = (int)(x & 0xff);
1143
! WriteFile(file, ch, 1, &size, NULL);
1149
x += ((uLong)get_byte(s))<<8;
1150
x += ((uLong)get_byte(s))<<16;
1152
! if (c == EOF) s->z_err = Z_DATA_ERROR;
1153
x += ((uLong)c)<<24;
1157
x += ((uLong)get_byte(s))<<8;
1158
x += ((uLong)get_byte(s))<<16;
1160
! if (c == -1) s->z_err = Z_DATA_ERROR;
1161
x += ((uLong)c)<<24;
1167
if (s->mode == 'w') {
1169
! return Z_STREAM_ERROR;
1171
err = do_flush (file, Z_FINISH);
1172
if (err != Z_OK) return destroy((gz_stream*)file);
1175
if (s->mode == 'w') {
1177
! return Z_STREAM_ERROR;
1179
err = do_flush (file, Z_FINISH);
1180
if (err != Z_OK) return destroy((gz_stream*)file);
1184
if (*errnum == Z_OK) return (const char*)"";
1186
! m = (char*)(*errnum == Z_ERRNO ? zstrerror(errno) : s->stream.msg);
1188
if (m == NULL || *m == '\0') m = (char*)ERR_MSG(s->z_err);
1192
if (*errnum == Z_OK) return (const char*)"";
1194
! m = (char*)(*errnum == Z_ERRNO ? zstrerror(GetLastError()) : s->stream.msg);
1196
if (m == NULL || *m == '\0') m = (char*)ERR_MSG(s->z_err);
1198
*** zlib113/minigzip.c Sat Jul 8 13:59:49 2000
1199
--- zlibwce/minigzip.c Sat Jul 8 13:58:29 2000
1203
/* minigzip.c -- simulate gzip using the zlib compression library
1204
* Copyright (C) 1995-1998 Jean-loup Gailly.
1205
+ * Copyright (C) 2000 Tenik Co.,Ltd.
1206
* For conditions of distribution and use, see copyright notice in zlib.h
1213
/* @(#) $Id: zlib.diff,v 1.1.1.1 2000/11/17 14:22:46 rocco Exp $ */
1215
+ #if defined(_WIN32_WCE)
1216
+ #if _WIN32_WCE < 211
1217
+ #error (f|w)printf functions is not support old WindowsCE.
1220
+ #include <windows.h>
1229
# include <sys/stat.h>
1232
! #if defined(MSDOS) || defined(OS2) || defined(WIN32)
1235
# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
1237
# include <sys/stat.h>
1240
! #if (defined(MSDOS) || defined(OS2) || defined(WIN32)) && !defined(_WIN32_WCE)
1243
# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
1251
void error OF((const char *msg));
1252
! void gz_compress OF((FILE *in, gzFile out));
1254
! int gz_compress_mmap OF((FILE *in, gzFile out));
1256
! void gz_uncompress OF((gzFile in, FILE *out));
1257
void file_compress OF((char *file, char *mode));
1258
void file_uncompress OF((char *file));
1259
int main OF((int argc, char *argv[]));
1264
+ #if defined(_WIN32_WCE)
1266
+ #define stderr stdout
1267
+ #define F_FILE HANDLE
1268
+ #define F_NULL INVALID_HANDLE_VALUE
1270
+ #define F_FILE FILE*
1271
+ #define F_NULL NULL
1276
void error OF((const char *msg));
1277
! void gz_compress OF((F_FILE in, gzFile out));
1279
! int gz_compress_mmap OF((F_FILE in, gzFile out));
1281
! void gz_uncompress OF((gzFile in, F_FILE out));
1282
void file_compress OF((char *file, char *mode));
1283
void file_uncompress OF((char *file));
1284
int main OF((int argc, char *argv[]));
1290
/* ===========================================================================
1291
* Compress input to output then close both files.
1294
void gz_compress(in, out)
1298
local char buf[BUFLEN];
1303
+ #if defined(_WIN32_WCE)
1310
+ dwError = GetLastError();
1311
+ if ( FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
1312
+ FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE |
1313
+ FORMAT_MESSAGE_IGNORE_INSERTS,
1316
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
1317
+ (LPTSTR) &lpMsgBuf,
1321
+ wprintf(TEXT("%S: %s\n"), msg, (LPTSTR)lpMsgBuf);
1322
+ LocalFree(lpMsgBuf);
1326
+ wprintf(TEXT("%S: Error #%d\n"), msg, dwError);
1330
+ int unlink(filename)
1331
+ const char *filename;
1333
+ TCHAR path[MAX_PATH];
1335
+ MultiByteToWideChar(CP_ACP, 0, filename, -1, path, MAX_PATH);
1336
+ return DeleteFile(path);
1340
/* ===========================================================================
1341
* Compress input to output then close both files.
1344
void gz_compress(in, out)
1348
local char buf[BUFLEN];
1352
if (gz_compress_mmap(in, out) == Z_OK) return;
1355
+ #if defined(_WIN32_WCE)
1356
+ if (!ReadFile(in, buf, sizeof(buf), &len, NULL)) {
1358
len = fread(buf, 1, sizeof(buf), in);
1368
if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err));
1370
+ #if defined(_WIN32_WCE)
1375
if (gzclose(out) != Z_OK) error("failed gzclose");
1380
* if success, Z_ERRNO otherwise.
1382
int gz_compress_mmap(in, out)
1388
* if success, Z_ERRNO otherwise.
1390
int gz_compress_mmap(in, out)
1398
void gz_uncompress(in, out)
1402
local char buf[BUFLEN];
1407
len = gzread(in, buf, sizeof(buf));
1410
void gz_uncompress(in, out)
1414
local char buf[BUFLEN];
1417
+ #if defined(_WIN32_WCE)
1422
len = gzread(in, buf, sizeof(buf));
1425
if (len < 0) error (gzerror(in, &err));
1426
if (len == 0) break;
1428
if ((int)fwrite(buf, 1, (unsigned)len, out) != len) {
1429
! error("failed fwrite");
1432
if (fclose(out)) error("failed fclose");
1434
if (gzclose(in) != Z_OK) error("failed gzclose");
1437
if (len < 0) error (gzerror(in, &err));
1438
if (len == 0) break;
1440
+ #if defined(_WIN32_WCE)
1441
+ if (!WriteFile(out, buf, (unsigned)len, &size, NULL) || size != len) {
1443
if ((int)fwrite(buf, 1, (unsigned)len, out) != len) {
1445
! error("failed fwrite");
1448
+ #if defined(_WIN32_WCE)
1449
+ if (!CloseHandle(out)) error("failed fclose");
1451
if (fclose(out)) error("failed fclose");
1454
if (gzclose(in) != Z_OK) error("failed gzclose");
1460
local char outfile[MAX_NAME_LEN];
1464
strcpy(outfile, file);
1465
strcat(outfile, GZ_SUFFIX);
1467
in = fopen(file, "rb");
1472
out = gzopen(outfile, mode);
1473
! if (out == NULL) {
1474
fprintf(stderr, "%s: can't gzopen %s\n", prog, outfile);
1480
local char outfile[MAX_NAME_LEN];
1483
+ #if defined(_WIN32_WCE)
1484
+ TCHAR path[MAX_PATH];
1487
strcpy(outfile, file);
1488
strcat(outfile, GZ_SUFFIX);
1490
+ #if defined(_WIN32_WCE)
1491
+ MultiByteToWideChar(CP_ACP, 0, file, -1, path, MAX_PATH);
1492
+ in = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
1494
in = fopen(file, "rb");
1496
! if (in == F_NULL) {
1500
out = gzopen(outfile, mode);
1501
! if (out == F_NULL) {
1502
fprintf(stderr, "%s: can't gzopen %s\n", prog, outfile);
1508
local char buf[MAX_NAME_LEN];
1509
char *infile, *outfile;
1512
int len = strlen(file);
1518
local char buf[MAX_NAME_LEN];
1519
char *infile, *outfile;
1522
int len = strlen(file);
1523
+ #if defined(_WIN32_WCE)
1524
+ TCHAR path[MAX_PATH];
1531
strcat(infile, GZ_SUFFIX);
1533
in = gzopen(infile, "rb");
1535
fprintf(stderr, "%s: can't gzopen %s\n", prog, infile);
1538
out = fopen(outfile, "wb");
1539
! if (out == NULL) {
1544
strcat(infile, GZ_SUFFIX);
1546
in = gzopen(infile, "rb");
1547
! if (in == F_NULL) {
1548
fprintf(stderr, "%s: can't gzopen %s\n", prog, infile);
1551
+ #if defined(_WIN32_WCE)
1552
+ MultiByteToWideChar(CP_ACP, 0, outfile, -1, path, MAX_PATH);
1553
+ out = CreateFile(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
1555
out = fopen(outfile, "wb");
1557
! if (out == F_NULL) {
1567
+ #if !defined(_WIN32_WCE)
1572
strcpy(outmode, "wb6 ");
1577
if (strcmp(*argv, "-d") == 0)
1579
else if (strcmp(*argv, "-f") == 0)
1581
else if (strcmp(*argv, "-h") == 0)
1583
else if ((*argv)[0] == '-' && (*argv)[1] >= '1' && (*argv)[1] <= '9' &&
1585
! outmode[2] = (*argv)[1];
1591
SET_BINARY_MODE(stdin);
1592
SET_BINARY_MODE(stdout);
1597
if (strcmp(*argv, "-d") == 0)
1599
else if (strcmp(*argv, "-f") == 0)
1601
else if (strcmp(*argv, "-h") == 0)
1603
else if ((*argv)[0] == '-' && (*argv)[1] >= '1' && (*argv)[1] <= '9' &&
1605
! outmode[2] = (*argv)[1];
1611
+ #if defined(_WIN32_WCE)
1612
+ wprintf(TEXT("Usage: minigzip [-d] [-f] [-h] [-1 to -9] [files...]\n"));
1613
+ wprintf(TEXT(" -d : decompress\n"));
1614
+ wprintf(TEXT(" -f : compress with Z_FILTERED\n"));
1615
+ wprintf(TEXT(" -h : compress with Z_HUFFMAN_ONLY\n"));
1616
+ wprintf(TEXT(" -1 to -9 : compression level\n"));
1618
SET_BINARY_MODE(stdin);
1619
SET_BINARY_MODE(stdout);
1624
if (file == NULL) error("can't gzdopen stdout");
1625
gz_compress(stdin, file);
1635
return 0; /* to avoid warning */
1638
+ #if defined(_WIN32_WCE)
1639
+ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR lpszCmdLine, int nCmdShow)
1641
+ #define SIZE_ARGV (32)
1643
+ char *argv[SIZE_ARGV];
1648
+ size = WideCharToMultiByte(CP_ACP, 0, lpszCmdLine, -1, NULL, 0, NULL, NULL);
1649
+ buff = (char *)malloc(size);
1650
+ size = WideCharToMultiByte(CP_ACP, 0, lpszCmdLine, -1, buff, size, NULL, NULL);
1653
+ argv[argc++] = "minigzip.exe";
1655
+ argv[argc++] = argp;
1657
+ if (*argp == ' ') {
1659
+ while (*argp && *argp == ' ') {
1662
+ if (*argp && argc < SIZE_ARGV) {
1663
+ argv[argc++] = argp;
1670
+ return main(argc, argv);
1673
*** zlib113/example.c Sat Jul 8 13:59:49 2000
1674
--- zlibwce/example.c Sat Jul 8 13:58:29 2000
1678
/* example.c -- usage example of the zlib compression library
1679
* Copyright (C) 1995-1998 Jean-loup Gailly.
1680
+ * Copyright (C) 2000 Tenik Co.,Ltd.
1681
* For conditions of distribution and use, see copyright notice in zlib.h
1684
/* @(#) $Id: zlib.diff,v 1.1.1.1 2000/11/17 14:22:46 rocco Exp $ */
1686
+ #if defined(_WIN32_WCE)
1687
+ #if _WIN32_WCE < 211
1688
+ #error (f|w)printf functions is not support old WindowsCE.
1690
+ #include <windows.h>
1700
# define TESTFILE "foo.gz"
1703
+ #if defined(_WIN32_WCE)
1704
+ #define calloc(x,y) malloc((x)*(y))
1706
+ #define stderr stdout
1707
+ #define F_NULL INVALID_HANDLE_VALUE
1709
+ #define F_NULL NULL
1712
#define CHECK_ERR(err, msg) { \
1713
if (err != Z_OK) { \
1714
fprintf(stderr, "%s error: %d\n", msg, err); \
1717
uLong dictId; /* Adler32 value of the dictionary */
1719
void test_compress OF((Byte *compr, uLong comprLen,
1720
! Byte *uncompr, uLong uncomprLen));
1721
void test_gzio OF((const char *out, const char *in,
1722
! Byte *uncompr, int uncomprLen));
1723
void test_deflate OF((Byte *compr, uLong comprLen));
1724
void test_inflate OF((Byte *compr, uLong comprLen,
1725
! Byte *uncompr, uLong uncomprLen));
1726
void test_large_deflate OF((Byte *compr, uLong comprLen,
1727
! Byte *uncompr, uLong uncomprLen));
1728
void test_large_inflate OF((Byte *compr, uLong comprLen,
1729
! Byte *uncompr, uLong uncomprLen));
1730
void test_flush OF((Byte *compr, uLong *comprLen));
1731
void test_sync OF((Byte *compr, uLong comprLen,
1732
! Byte *uncompr, uLong uncomprLen));
1733
void test_dict_deflate OF((Byte *compr, uLong comprLen));
1734
void test_dict_inflate OF((Byte *compr, uLong comprLen,
1735
! Byte *uncompr, uLong uncomprLen));
1736
int main OF((int argc, char *argv[]));
1738
/* ===========================================================================
1740
uLong dictId; /* Adler32 value of the dictionary */
1742
void test_compress OF((Byte *compr, uLong comprLen,
1743
! Byte *uncompr, uLong uncomprLen));
1744
void test_gzio OF((const char *out, const char *in,
1745
! Byte *uncompr, int uncomprLen));
1746
void test_deflate OF((Byte *compr, uLong comprLen));
1747
void test_inflate OF((Byte *compr, uLong comprLen,
1748
! Byte *uncompr, uLong uncomprLen));
1749
void test_large_deflate OF((Byte *compr, uLong comprLen,
1750
! Byte *uncompr, uLong uncomprLen));
1751
void test_large_inflate OF((Byte *compr, uLong comprLen,
1752
! Byte *uncompr, uLong uncomprLen));
1753
void test_flush OF((Byte *compr, uLong *comprLen));
1754
void test_sync OF((Byte *compr, uLong comprLen,
1755
! Byte *uncompr, uLong uncomprLen));
1756
void test_dict_deflate OF((Byte *compr, uLong comprLen));
1757
void test_dict_inflate OF((Byte *compr, uLong comprLen,
1758
! Byte *uncompr, uLong uncomprLen));
1759
int main OF((int argc, char *argv[]));
1761
/* ===========================================================================
1765
if (strcmp((char*)uncompr, hello)) {
1766
fprintf(stderr, "bad uncompress\n");
1769
printf("uncompress(): %s\n", (char *)uncompr);
1773
if (strcmp((char*)uncompr, hello)) {
1774
fprintf(stderr, "bad uncompress\n");
1777
printf("uncompress(): %s\n", (char *)uncompr);
1783
file = gzopen(out, "wb");
1784
! if (file == NULL) {
1785
fprintf(stderr, "gzopen error\n");
1791
file = gzopen(out, "wb");
1792
! if (file == F_NULL) {
1793
fprintf(stderr, "gzopen error\n");
1799
if (gzputs(file, "ello") != 4) {
1800
fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err));
1803
if (gzprintf(file, ", %s!", "hello") != 8) {
1804
fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err));
1807
gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
1810
file = gzopen(in, "rb");
1811
! if (file == NULL) {
1812
fprintf(stderr, "gzopen error\n");
1814
strcpy((char*)uncompr, "garbage");
1817
if (gzputs(file, "ello") != 4) {
1818
fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err));
1821
if (gzprintf(file, ", %s!", "hello") != 8) {
1822
fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err));
1825
gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
1828
file = gzopen(in, "rb");
1829
! if (file == F_NULL) {
1830
fprintf(stderr, "gzopen error\n");
1832
strcpy((char*)uncompr, "garbage");
1835
uncomprLen = gzread(file, uncompr, (unsigned)uncomprLen);
1836
if (uncomprLen != len) {
1837
fprintf(stderr, "gzread err: %s\n", gzerror(file, &err));
1840
if (strcmp((char*)uncompr, hello)) {
1841
fprintf(stderr, "bad gzread: %s\n", (char*)uncompr);
1844
printf("gzread(): %s\n", (char *)uncompr);
1847
uncomprLen = gzread(file, uncompr, (unsigned)uncomprLen);
1848
if (uncomprLen != len) {
1849
fprintf(stderr, "gzread err: %s\n", gzerror(file, &err));
1852
if (strcmp((char*)uncompr, hello)) {
1853
fprintf(stderr, "bad gzread: %s\n", (char*)uncompr);
1856
printf("gzread(): %s\n", (char *)uncompr);
1861
pos = gzseek(file, -8L, SEEK_CUR);
1862
if (pos != 6 || gztell(file) != pos) {
1863
! fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n",
1864
! (long)pos, (long)gztell(file));
1868
if (gzgetc(file) != ' ') {
1869
! fprintf(stderr, "gzgetc error\n");
1873
gzgets(file, (char*)uncompr, uncomprLen);
1876
pos = gzseek(file, -8L, SEEK_CUR);
1877
if (pos != 6 || gztell(file) != pos) {
1878
! fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n",
1879
! (long)pos, (long)gztell(file));
1883
if (gzgetc(file) != ' ') {
1884
! fprintf(stderr, "gzgetc error\n");
1888
gzgets(file, (char*)uncompr, uncomprLen);
1891
uncomprLen = strlen((char*)uncompr);
1892
if (uncomprLen != 6) { /* "hello!" */
1893
fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err));
1896
if (strcmp((char*)uncompr, hello+7)) {
1897
fprintf(stderr, "bad gzgets after gzseek\n");
1900
printf("gzgets() after gzseek: %s\n", (char *)uncompr);
1903
uncomprLen = strlen((char*)uncompr);
1904
if (uncomprLen != 6) { /* "hello!" */
1905
fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err));
1908
if (strcmp((char*)uncompr, hello+7)) {
1909
fprintf(stderr, "bad gzgets after gzseek\n");
1912
printf("gzgets() after gzseek: %s\n", (char *)uncompr);
1917
if (strcmp((char*)uncompr, hello)) {
1918
fprintf(stderr, "bad inflate\n");
1921
printf("inflate(): %s\n", (char *)uncompr);
1925
if (strcmp((char*)uncompr, hello)) {
1926
fprintf(stderr, "bad inflate\n");
1929
printf("inflate(): %s\n", (char *)uncompr);
1933
CHECK_ERR(err, "deflate");
1934
if (c_stream.avail_in != 0) {
1935
fprintf(stderr, "deflate not greedy\n");
1939
/* Feed in already compressed data and switch to no compression: */
1941
CHECK_ERR(err, "deflate");
1942
if (c_stream.avail_in != 0) {
1943
fprintf(stderr, "deflate not greedy\n");
1947
/* Feed in already compressed data and switch to no compression: */
1950
err = deflate(&c_stream, Z_FINISH);
1951
if (err != Z_STREAM_END) {
1952
fprintf(stderr, "deflate should report Z_STREAM_END\n");
1955
err = deflateEnd(&c_stream);
1956
CHECK_ERR(err, "deflateEnd");
1958
err = deflate(&c_stream, Z_FINISH);
1959
if (err != Z_STREAM_END) {
1960
fprintf(stderr, "deflate should report Z_STREAM_END\n");
1963
err = deflateEnd(&c_stream);
1964
CHECK_ERR(err, "deflateEnd");
1969
d_stream.next_out = uncompr; /* discard the output */
1970
! d_stream.avail_out = (uInt)uncomprLen;
1971
err = inflate(&d_stream, Z_NO_FLUSH);
1972
if (err == Z_STREAM_END) break;
1973
CHECK_ERR(err, "large inflate");
1977
d_stream.next_out = uncompr; /* discard the output */
1978
! d_stream.avail_out = (uInt)uncomprLen;
1979
err = inflate(&d_stream, Z_NO_FLUSH);
1980
if (err == Z_STREAM_END) break;
1981
CHECK_ERR(err, "large inflate");
1985
if (d_stream.total_out != 2*uncomprLen + comprLen/2) {
1986
fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out);
1989
printf("large_inflate(): OK\n");
1993
if (d_stream.total_out != 2*uncomprLen + comprLen/2) {
1994
fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out);
1997
printf("large_inflate(): OK\n");
2001
if (err != Z_DATA_ERROR) {
2002
fprintf(stderr, "inflate should report DATA_ERROR\n");
2003
/* Because of incorrect adler32 */
2006
err = inflateEnd(&d_stream);
2007
CHECK_ERR(err, "inflateEnd");
2009
if (err != Z_DATA_ERROR) {
2010
fprintf(stderr, "inflate should report DATA_ERROR\n");
2011
/* Because of incorrect adler32 */
2014
err = inflateEnd(&d_stream);
2015
CHECK_ERR(err, "inflateEnd");
2018
CHECK_ERR(err, "deflateInit");
2020
err = deflateSetDictionary(&c_stream,
2021
! (const Bytef*)dictionary, sizeof(dictionary));
2022
CHECK_ERR(err, "deflateSetDictionary");
2024
dictId = c_stream.adler;
2026
CHECK_ERR(err, "deflateInit");
2028
err = deflateSetDictionary(&c_stream,
2029
! (const Bytef*)dictionary, sizeof(dictionary));
2030
CHECK_ERR(err, "deflateSetDictionary");
2032
dictId = c_stream.adler;
2035
err = deflate(&c_stream, Z_FINISH);
2036
if (err != Z_STREAM_END) {
2037
fprintf(stderr, "deflate should report Z_STREAM_END\n");
2040
err = deflateEnd(&c_stream);
2041
CHECK_ERR(err, "deflateEnd");
2043
err = deflate(&c_stream, Z_FINISH);
2044
if (err != Z_STREAM_END) {
2045
fprintf(stderr, "deflate should report Z_STREAM_END\n");
2048
err = deflateEnd(&c_stream);
2049
CHECK_ERR(err, "deflateEnd");
2053
err = inflate(&d_stream, Z_NO_FLUSH);
2054
if (err == Z_STREAM_END) break;
2055
! if (err == Z_NEED_DICT) {
2056
! if (d_stream.adler != dictId) {
2057
! fprintf(stderr, "unexpected dictionary");
2060
! err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,
2061
! sizeof(dictionary));
2063
CHECK_ERR(err, "inflate with dict");
2068
err = inflate(&d_stream, Z_NO_FLUSH);
2069
if (err == Z_STREAM_END) break;
2070
! if (err == Z_NEED_DICT) {
2071
! if (d_stream.adler != dictId) {
2072
! fprintf(stderr, "unexpected dictionary");
2075
! err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,
2076
! sizeof(dictionary));
2078
CHECK_ERR(err, "inflate with dict");
2084
if (strcmp((char*)uncompr, hello)) {
2085
fprintf(stderr, "bad inflate with dict\n");
2088
printf("inflate with dictionary: %s\n", (char *)uncompr);
2092
if (strcmp((char*)uncompr, hello)) {
2093
fprintf(stderr, "bad inflate with dict\n");
2096
printf("inflate with dictionary: %s\n", (char *)uncompr);
2101
if (compr == Z_NULL || uncompr == Z_NULL) {
2102
printf("out of memory\n");
2105
test_compress(compr, comprLen, uncompr, uncomprLen);
2107
test_gzio((argc > 1 ? argv[1] : TESTFILE),
2108
(argc > 2 ? argv[2] : TESTFILE),
2109
! uncompr, (int)uncomprLen);
2111
test_deflate(compr, comprLen);
2112
test_inflate(compr, comprLen, uncompr, uncomprLen);
2115
if (compr == Z_NULL || uncompr == Z_NULL) {
2116
printf("out of memory\n");
2119
test_compress(compr, comprLen, uncompr, uncomprLen);
2121
test_gzio((argc > 1 ? argv[1] : TESTFILE),
2122
(argc > 2 ? argv[2] : TESTFILE),
2123
! uncompr, (int)uncomprLen);
2125
test_deflate(compr, comprLen);
2126
test_inflate(compr, comprLen, uncompr, uncomprLen);
2131
return 0; /* to avoid warning */
2134
+ #if defined(_WIN32_WCE)
2135
+ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR lpszCmdLine, int nCmdShow)
2137
+ #define SIZE_ARGV (32)
2139
+ char *argv[SIZE_ARGV];
2144
+ size = WideCharToMultiByte(CP_ACP, 0, lpszCmdLine, -1, NULL, 0, NULL, NULL);
2145
+ buff = (char *)malloc(size);
2146
+ size = WideCharToMultiByte(CP_ACP, 0, lpszCmdLine, -1, buff, size, NULL, NULL);
2149
+ argv[argc++] = "example.exe";
2151
+ argv[argc++] = argp;
2153
+ if (*argp == ' ') {
2155
+ while (*argp && *argp == ' ') {
2158
+ if (*argp && argc < SIZE_ARGV) {
2159
+ argv[argc++] = argp;
2166
+ return main(argc, argv);