diff options
Diffstat (limited to 'gunzip.c')
-rw-r--r-- | gunzip.c | 151 |
1 files changed, 11 insertions, 140 deletions
@@ -367,25 +367,23 @@ void send_bits (int value, int length); | |||
367 | unsigned bi_reverse (unsigned value, int length); | 367 | unsigned bi_reverse (unsigned value, int length); |
368 | void bi_windup (void); | 368 | void bi_windup (void); |
369 | void copy_block (char *buf, unsigned len, int header); | 369 | void copy_block (char *buf, unsigned len, int header); |
370 | extern int (*read_buf) (char *buf, unsigned size); | ||
371 | 370 | ||
372 | /* in util.c: */ | 371 | /* in util.c: */ |
373 | extern int copy (int in, int out); | ||
374 | extern ulg updcrc (uch * s, unsigned n); | 372 | extern ulg updcrc (uch * s, unsigned n); |
375 | extern void clear_bufs (void); | 373 | extern void clear_bufs (void); |
376 | extern int fill_inbuf (int eof_ok); | 374 | static int fill_inbuf (int eof_ok); |
377 | extern void flush_outbuf (void); | 375 | extern void flush_outbuf (void); |
378 | extern void flush_window (void); | 376 | static void flush_window (void); |
379 | extern void write_buf (int fd, void * buf, unsigned cnt); | 377 | extern void write_buf (int fd, void * buf, unsigned cnt); |
380 | 378 | ||
381 | #ifndef __linux__ | 379 | #ifndef __linux__ |
382 | extern char *basename (char *fname); | 380 | static char *basename (char *fname); |
383 | #endif /* not __linux__ */ | 381 | #endif /* not __linux__ */ |
384 | extern void read_error (void); | 382 | void read_error_msg (void); |
385 | extern void write_error (void); | 383 | void write_error_msg (void); |
386 | 384 | ||
387 | /* in inflate.c */ | 385 | /* in inflate.c */ |
388 | extern int inflate (void); | 386 | static int inflate (void); |
389 | 387 | ||
390 | /* #include "lzw.h" */ | 388 | /* #include "lzw.h" */ |
391 | 389 | ||
@@ -450,133 +448,6 @@ extern int unlzw (int in, int out); | |||
450 | # undef LZW | 448 | # undef LZW |
451 | #endif | 449 | #endif |
452 | 450 | ||
453 | /* #include "getopt.h" */ | ||
454 | |||
455 | /* Declarations for getopt. | ||
456 | Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc. | ||
457 | |||
458 | This program is free software; you can redistribute it and/or modify it | ||
459 | under the terms of the GNU General Public License as published by the | ||
460 | Free Software Foundation; either version 2, or (at your option) any | ||
461 | later version. | ||
462 | |||
463 | This program is distributed in the hope that it will be useful, | ||
464 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
465 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
466 | GNU General Public License for more details. | ||
467 | |||
468 | You should have received a copy of the GNU General Public License | ||
469 | along with this program; if not, write to the Free Software | ||
470 | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
471 | |||
472 | #ifndef _GETOPT_H | ||
473 | #define _GETOPT_H 1 | ||
474 | |||
475 | #ifdef __cplusplus | ||
476 | extern "C" { | ||
477 | #endif | ||
478 | /* For communication from `getopt' to the caller. | ||
479 | When `getopt' finds an option that takes an argument, | ||
480 | the argument value is returned here. | ||
481 | Also, when `ordering' is RETURN_IN_ORDER, | ||
482 | each non-option ARGV-element is returned here. */ | ||
483 | extern char *optarg; | ||
484 | |||
485 | /* Index in ARGV of the next element to be scanned. | ||
486 | This is used for communication to and from the caller | ||
487 | and for communication between successive calls to `getopt'. | ||
488 | |||
489 | On entry to `getopt', zero means this is the first call; initialize. | ||
490 | |||
491 | When `getopt' returns EOF, this is the index of the first of the | ||
492 | non-option elements that the caller should itself scan. | ||
493 | |||
494 | Otherwise, `optind' communicates from one call to the next | ||
495 | how much of ARGV has been scanned so far. */ | ||
496 | |||
497 | extern int optind; | ||
498 | |||
499 | /* Callers store zero here to inhibit the error message `getopt' prints | ||
500 | for unrecognized options. */ | ||
501 | |||
502 | extern int opterr; | ||
503 | |||
504 | /* Set to an option character which was unrecognized. */ | ||
505 | |||
506 | extern int optopt; | ||
507 | |||
508 | /* Describe the long-named options requested by the application. | ||
509 | The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector | ||
510 | of `struct option' terminated by an element containing a name which is | ||
511 | zero. | ||
512 | |||
513 | The field `has_arg' is: | ||
514 | no_argument (or 0) if the option does not take an argument, | ||
515 | required_argument (or 1) if the option requires an argument, | ||
516 | optional_argument (or 2) if the option takes an optional argument. | ||
517 | |||
518 | If the field `flag' is not NULL, it points to a variable that is set | ||
519 | to the value given in the field `val' when the option is found, but | ||
520 | left unchanged if the option is not found. | ||
521 | |||
522 | To have a long-named option do something other than set an `int' to | ||
523 | a compiled-in constant, such as set a value from `optarg', set the | ||
524 | option's `flag' field to zero and its `val' field to a nonzero | ||
525 | value (the equivalent single-letter option character, if there is | ||
526 | one). For long options that have a zero `flag' field, `getopt' | ||
527 | returns the contents of the `val' field. */ | ||
528 | |||
529 | struct option { | ||
530 | #if __STDC__ | ||
531 | const char *name; | ||
532 | #else | ||
533 | char *name; | ||
534 | #endif | ||
535 | /* has_arg can't be an enum because some compilers complain about | ||
536 | type mismatches in all the code that assumes it is an int. */ | ||
537 | int has_arg; | ||
538 | int *flag; | ||
539 | int val; | ||
540 | }; | ||
541 | |||
542 | /* Names for the values of the `has_arg' field of `struct option'. */ | ||
543 | |||
544 | #define no_argument 0 | ||
545 | #define required_argument 1 | ||
546 | #define optional_argument 2 | ||
547 | |||
548 | #if __STDC__ || defined(PROTO) | ||
549 | #if defined(__GNU_LIBRARY__) | ||
550 | /* Many other libraries have conflicting prototypes for getopt, with | ||
551 | differences in the consts, in stdlib.h. To avoid compilation | ||
552 | errors, only prototype getopt for the GNU C library. */ | ||
553 | extern int getopt(int argc, char *const *argv, const char *shortopts); | ||
554 | #endif /* not __GNU_LIBRARY__ */ | ||
555 | extern int getopt_long(int argc, char *const *argv, | ||
556 | const char *shortopts, | ||
557 | const struct option *longopts, int *longind); | ||
558 | extern int getopt_long_only(int argc, char *const *argv, | ||
559 | const char *shortopts, | ||
560 | const struct option *longopts, | ||
561 | int *longind); | ||
562 | |||
563 | /* Internal only. Users should not call this directly. */ | ||
564 | extern int _getopt_internal(int argc, char *const *argv, | ||
565 | const char *shortopts, | ||
566 | const struct option *longopts, | ||
567 | int *longind, int long_only); | ||
568 | #else /* not __STDC__ */ | ||
569 | extern int getopt(); | ||
570 | extern int getopt_long(); | ||
571 | extern int getopt_long_only(); | ||
572 | |||
573 | extern int _getopt_internal(); | ||
574 | #endif /* not __STDC__ */ | ||
575 | |||
576 | #ifdef __cplusplus | ||
577 | } | ||
578 | #endif | ||
579 | #endif /* _GETOPT_H */ | ||
580 | #include <time.h> | 451 | #include <time.h> |
581 | #include <fcntl.h> | 452 | #include <fcntl.h> |
582 | #include <unistd.h> | 453 | #include <unistd.h> |
@@ -1161,7 +1032,7 @@ unsigned n; /* number of bytes in s[] */ | |||
1161 | /* =========================================================================== | 1032 | /* =========================================================================== |
1162 | * Clear input and output buffers | 1033 | * Clear input and output buffers |
1163 | */ | 1034 | */ |
1164 | void clear_bufs() | 1035 | void clear_bufs(void) |
1165 | { | 1036 | { |
1166 | outcnt = 0; | 1037 | outcnt = 0; |
1167 | insize = inptr = 0; | 1038 | insize = inptr = 0; |
@@ -1189,7 +1060,7 @@ int eof_ok; /* set if EOF acceptable as a result */ | |||
1189 | if (insize == 0) { | 1060 | if (insize == 0) { |
1190 | if (eof_ok) | 1061 | if (eof_ok) |
1191 | return EOF; | 1062 | return EOF; |
1192 | read_error(); | 1063 | read_error_msg(); |
1193 | } | 1064 | } |
1194 | bytes_in += (ulg) insize; | 1065 | bytes_in += (ulg) insize; |
1195 | inptr = 1; | 1066 | inptr = 1; |
@@ -1240,7 +1111,7 @@ unsigned cnt; | |||
1240 | 1111 | ||
1241 | while ((n = write(fd, buf, cnt)) != cnt) { | 1112 | while ((n = write(fd, buf, cnt)) != cnt) { |
1242 | if (n == (unsigned) (-1)) { | 1113 | if (n == (unsigned) (-1)) { |
1243 | write_error(); | 1114 | write_error_msg(); |
1244 | } | 1115 | } |
1245 | cnt -= n; | 1116 | cnt -= n; |
1246 | buf = (void *) ((char *) buf + n); | 1117 | buf = (void *) ((char *) buf + n); |
@@ -1306,7 +1177,7 @@ const char *reject; | |||
1306 | /* ======================================================================== | 1177 | /* ======================================================================== |
1307 | * Error handlers. | 1178 | * Error handlers. |
1308 | */ | 1179 | */ |
1309 | void read_error() | 1180 | void read_error_msg() |
1310 | { | 1181 | { |
1311 | fprintf(stderr, "\n"); | 1182 | fprintf(stderr, "\n"); |
1312 | if (errno != 0) { | 1183 | if (errno != 0) { |
@@ -1317,7 +1188,7 @@ void read_error() | |||
1317 | abort_gzip(); | 1188 | abort_gzip(); |
1318 | } | 1189 | } |
1319 | 1190 | ||
1320 | void write_error() | 1191 | void write_error_msg() |
1321 | { | 1192 | { |
1322 | fprintf(stderr, "\n"); | 1193 | fprintf(stderr, "\n"); |
1323 | perror(""); | 1194 | perror(""); |