diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2011-09-09 23:24:52 -0700 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2011-09-09 23:24:52 -0700 |
commit | 9c3a5830218c4e7fff23b8fc4386269db77a03a9 (patch) | |
tree | 913542049433ae44de55d22913f6bca921f2dc15 /examples/gun.c | |
parent | 6b8233bfe00e79134cb1b84fc49d4f750a797f79 (diff) | |
download | zlib-1.2.2.4.tar.gz zlib-1.2.2.4.tar.bz2 zlib-1.2.2.4.zip |
zlib 1.2.2.4v1.2.2.4
Diffstat (limited to 'examples/gun.c')
-rw-r--r-- | examples/gun.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/examples/gun.c b/examples/gun.c index 1c0d8e5..bfec590 100644 --- a/examples/gun.c +++ b/examples/gun.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* gun.c -- simple gunzip to give an example of the use of inflateBack() | 1 | /* gun.c -- simple gunzip to give an example of the use of inflateBack() |
2 | * Copyright (C) 2003, 2005 Mark Adler | 2 | * Copyright (C) 2003, 2005 Mark Adler |
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 | Version 1.2 20 March 2005 Mark Adler */ | 4 | Version 1.3 12 June 2005 Mark Adler */ |
5 | 5 | ||
6 | /* Version history: | 6 | /* Version history: |
7 | 1.0 16 Feb 2003 First version for testing of inflateBack() | 7 | 1.0 16 Feb 2003 First version for testing of inflateBack() |
@@ -14,6 +14,7 @@ | |||
14 | Add a bunch of comments | 14 | Add a bunch of comments |
15 | 1.2 20 Mar 2005 Add Unix compress (LZW) decompression | 15 | 1.2 20 Mar 2005 Add Unix compress (LZW) decompression |
16 | Copy file attributes from input file to output file | 16 | Copy file attributes from input file to output file |
17 | 1.3 12 Jun 2005 Add casts for error messages [Oberhumer] | ||
17 | */ | 18 | */ |
18 | 19 | ||
19 | /* | 20 | /* |
@@ -221,12 +222,12 @@ local int lunpipe(unsigned have, unsigned char *next, struct ind *indp, | |||
221 | if (last == -1) | 222 | if (last == -1) |
222 | return Z_BUF_ERROR; | 223 | return Z_BUF_ERROR; |
223 | if (flags & 0x60) { | 224 | if (flags & 0x60) { |
224 | strm->msg = "unknown lzw flags set"; | 225 | strm->msg = (char *)"unknown lzw flags set"; |
225 | return Z_DATA_ERROR; | 226 | return Z_DATA_ERROR; |
226 | } | 227 | } |
227 | max = flags & 0x1f; | 228 | max = flags & 0x1f; |
228 | if (max < 9 || max > 16) { | 229 | if (max < 9 || max > 16) { |
229 | strm->msg = "lzw bits out of range"; | 230 | strm->msg = (char *)"lzw bits out of range"; |
230 | return Z_DATA_ERROR; | 231 | return Z_DATA_ERROR; |
231 | } | 232 | } |
232 | if (max == 9) /* 9 doesn't really mean 9 */ | 233 | if (max == 9) /* 9 doesn't really mean 9 */ |
@@ -246,7 +247,7 @@ local int lunpipe(unsigned have, unsigned char *next, struct ind *indp, | |||
246 | if (NEXT() == -1) /* missing a bit */ | 247 | if (NEXT() == -1) /* missing a bit */ |
247 | return Z_BUF_ERROR; | 248 | return Z_BUF_ERROR; |
248 | if (last & 1) { /* code must be < 256 */ | 249 | if (last & 1) { /* code must be < 256 */ |
249 | strm->msg = "invalid lzw code"; | 250 | strm->msg = (char *)"invalid lzw code"; |
250 | return Z_DATA_ERROR; | 251 | return Z_DATA_ERROR; |
251 | } | 252 | } |
252 | rem = (unsigned)last >> 1; /* remaining 7 bits */ | 253 | rem = (unsigned)last >> 1; /* remaining 7 bits */ |
@@ -313,7 +314,7 @@ local int lunpipe(unsigned have, unsigned char *next, struct ind *indp, | |||
313 | to detect random or corrupted input after a compress header. | 314 | to detect random or corrupted input after a compress header. |
314 | In any case, the prev > end check must be retained. */ | 315 | In any case, the prev > end check must be retained. */ |
315 | if (code != end + 1 || prev > end) { | 316 | if (code != end + 1 || prev > end) { |
316 | strm->msg = "invalid lzw code"; | 317 | strm->msg = (char *)"invalid lzw code"; |
317 | return Z_DATA_ERROR; | 318 | return Z_DATA_ERROR; |
318 | } | 319 | } |
319 | match[stack++] = (unsigned char)final; | 320 | match[stack++] = (unsigned char)final; |
@@ -394,7 +395,7 @@ local int gunpipe(z_stream *strm, int infile, int outfile) | |||
394 | break; /* empty gzip stream is ok */ | 395 | break; /* empty gzip stream is ok */ |
395 | } | 396 | } |
396 | if (last != 31 || (NEXT() != 139 && last != 157)) { | 397 | if (last != 31 || (NEXT() != 139 && last != 157)) { |
397 | strm->msg = "incorrect header check"; | 398 | strm->msg = (char *)"incorrect header check"; |
398 | ret = first ? Z_DATA_ERROR : Z_ERRNO; | 399 | ret = first ? Z_DATA_ERROR : Z_ERRNO; |
399 | break; /* not a gzip or compress header */ | 400 | break; /* not a gzip or compress header */ |
400 | } | 401 | } |
@@ -410,7 +411,7 @@ local int gunpipe(z_stream *strm, int infile, int outfile) | |||
410 | ret = Z_BUF_ERROR; | 411 | ret = Z_BUF_ERROR; |
411 | if (NEXT() != 8) { /* only deflate method allowed */ | 412 | if (NEXT() != 8) { /* only deflate method allowed */ |
412 | if (last == -1) break; | 413 | if (last == -1) break; |
413 | strm->msg = "unknown compression method"; | 414 | strm->msg = (char *)"unknown compression method"; |
414 | ret = Z_DATA_ERROR; | 415 | ret = Z_DATA_ERROR; |
415 | break; | 416 | break; |
416 | } | 417 | } |
@@ -423,7 +424,7 @@ local int gunpipe(z_stream *strm, int infile, int outfile) | |||
423 | NEXT(); | 424 | NEXT(); |
424 | if (last == -1) break; | 425 | if (last == -1) break; |
425 | if (flags & 0xe0) { | 426 | if (flags & 0xe0) { |
426 | strm->msg = "unknown header flags set"; | 427 | strm->msg = (char *)"unknown header flags set"; |
427 | ret = Z_DATA_ERROR; | 428 | ret = Z_DATA_ERROR; |
428 | break; | 429 | break; |
429 | } | 430 | } |
@@ -476,7 +477,7 @@ local int gunpipe(z_stream *strm, int infile, int outfile) | |||
476 | NEXT() != ((outd.crc >> 24) & 0xff)) { | 477 | NEXT() != ((outd.crc >> 24) & 0xff)) { |
477 | /* crc error */ | 478 | /* crc error */ |
478 | if (last != -1) { | 479 | if (last != -1) { |
479 | strm->msg = "incorrect data check"; | 480 | strm->msg = (char *)"incorrect data check"; |
480 | ret = Z_DATA_ERROR; | 481 | ret = Z_DATA_ERROR; |
481 | } | 482 | } |
482 | break; | 483 | break; |
@@ -487,7 +488,7 @@ local int gunpipe(z_stream *strm, int infile, int outfile) | |||
487 | NEXT() != ((outd.total >> 24) & 0xff)) { | 488 | NEXT() != ((outd.total >> 24) & 0xff)) { |
488 | /* length error */ | 489 | /* length error */ |
489 | if (last != -1) { | 490 | if (last != -1) { |
490 | strm->msg = "incorrect length check"; | 491 | strm->msg = (char *)"incorrect length check"; |
491 | ret = Z_DATA_ERROR; | 492 | ret = Z_DATA_ERROR; |
492 | } | 493 | } |
493 | break; | 494 | break; |
@@ -641,7 +642,7 @@ int main(int argc, char **argv) | |||
641 | argv++; | 642 | argv++; |
642 | test = 0; | 643 | test = 0; |
643 | if (argc && strcmp(*argv, "-h") == 0) { | 644 | if (argc && strcmp(*argv, "-h") == 0) { |
644 | fprintf(stderr, "gun 1.2 (20 Mar 2005)\n"); | 645 | fprintf(stderr, "gun 1.3 (12 Jun 2005)\n"); |
645 | fprintf(stderr, "Copyright (c) 2005 Mark Adler\n"); | 646 | fprintf(stderr, "Copyright (c) 2005 Mark Adler\n"); |
646 | fprintf(stderr, "usage: gun [-t] [file1.gz [file2.Z ...]]\n"); | 647 | fprintf(stderr, "usage: gun [-t] [file1.gz [file2.Z ...]]\n"); |
647 | return 0; | 648 | return 0; |