diff options
Diffstat (limited to 'gzip.c')
-rw-r--r-- | gzip.c | 191 |
1 files changed, 91 insertions, 100 deletions
@@ -1,16 +1,42 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* gzip.c -- this is a stripped down version of gzip I put into busybox, it does | 2 | /* |
3 | * only standard in to standard out with -9 compression. It also requires the | 3 | * Gzip implementation for busybox |
4 | * zcat module for some important functions. | 4 | * |
5 | * Based on GNU gzip Copyright (C) 1992-1993 Jean-loup Gailly. | ||
6 | * | ||
7 | * Originally adjusted for busybox by Charles P. Wright <cpw@unix.asb.com> | ||
8 | * "this is a stripped down version of gzip I put into busybox, it does | ||
9 | * only standard in to standard out with -9 compression. It also requires | ||
10 | * the zcat module for some important functions." | ||
11 | * | ||
12 | * Adjusted further by Erik Andersen <andersen@lineo.com>, <andersee@debian.org> | ||
13 | * to support files as well as stdin/stdout, and to generally behave itself wrt | ||
14 | * command line handling. | ||
15 | * | ||
16 | * This program is free software; you can redistribute it and/or modify | ||
17 | * it under the terms of the GNU General Public License as published by | ||
18 | * the Free Software Foundation; either version 2 of the License, or | ||
19 | * (at your option) any later version. | ||
20 | * | ||
21 | * This program is distributed in the hope that it will be useful, | ||
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
24 | * General Public License for more details. | ||
25 | * | ||
26 | * You should have received a copy of the GNU General Public License | ||
27 | * along with this program; if not, write to the Free Software | ||
28 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
5 | * | 29 | * |
6 | * Charles P. Wright <cpw@unix.asb.com> | ||
7 | */ | 30 | */ |
31 | |||
8 | #include "internal.h" | 32 | #include "internal.h" |
9 | #ifdef BB_GZIP | ||
10 | 33 | ||
11 | //#ifndef BB_ZCAT | 34 | /* These defines are very important for BusyBox. Without these, |
12 | //#error you need zcat to have gzip support! | 35 | * huge chunks of ram are pre-allocated making the BusyBox bss |
13 | //#endif | 36 | * size Freaking Huge(tm), which is a bad thing.*/ |
37 | #define SMALL_MEM | ||
38 | #define DYN_ALLOC | ||
39 | |||
14 | 40 | ||
15 | static const char gzip_usage[] = | 41 | static const char gzip_usage[] = |
16 | "gzip [OPTION]... FILE\n\n" | 42 | "gzip [OPTION]... FILE\n\n" |
@@ -21,42 +47,12 @@ static const char gzip_usage[] = | |||
21 | "\t-c\tWrite output to standard output instead of FILE.gz\n"; | 47 | "\t-c\tWrite output to standard output instead of FILE.gz\n"; |
22 | 48 | ||
23 | 49 | ||
24 | /* gzip.h -- common declarations for all gzip modules | ||
25 | * Copyright (C) 1992-1993 Jean-loup Gailly. | ||
26 | * This is free software; you can redistribute it and/or modify it under the | ||
27 | * terms of the GNU General Public License, see the file COPYING. | ||
28 | */ | ||
29 | |||
30 | #if defined(__STDC__) || defined(PROTO) | ||
31 | # define OF(args) args | ||
32 | #else | ||
33 | # define OF(args) () | ||
34 | #endif | ||
35 | |||
36 | #ifdef __STDC__ | ||
37 | typedef void *voidp; | ||
38 | #else | ||
39 | typedef char *voidp; | ||
40 | #endif | ||
41 | |||
42 | /* I don't like nested includes, but the string and io functions are used | 50 | /* I don't like nested includes, but the string and io functions are used |
43 | * too often | 51 | * too often |
44 | */ | 52 | */ |
45 | #include <stdio.h> | 53 | #include <stdio.h> |
46 | #if !defined(NO_STRING_H) || defined(STDC_HEADERS) | 54 | #include <string.h> |
47 | # include <string.h> | 55 | #define memzero(s, n) memset ((void *)(s), 0, (n)) |
48 | # if !defined(STDC_HEADERS) && !defined(NO_MEMORY_H) && !defined(__GNUC__) | ||
49 | # include <memory.h> | ||
50 | # endif | ||
51 | # define memzero(s, n) memset ((voidp)(s), 0, (n)) | ||
52 | #else | ||
53 | # include <strings.h> | ||
54 | # define strchr index | ||
55 | # define strrchr rindex | ||
56 | # define memcpy(d, s, n) bcopy((s), (d), (n)) | ||
57 | # define memcmp(s1, s2, n) bcmp((s1), (s2), (n)) | ||
58 | # define memzero(s, n) bzero((s), (n)) | ||
59 | #endif | ||
60 | 56 | ||
61 | #ifndef RETSIGTYPE | 57 | #ifndef RETSIGTYPE |
62 | # define RETSIGTYPE void | 58 | # define RETSIGTYPE void |
@@ -121,13 +117,13 @@ extern int method; /* compression method */ | |||
121 | #endif | 117 | #endif |
122 | 118 | ||
123 | #ifdef DYN_ALLOC | 119 | #ifdef DYN_ALLOC |
124 | # define EXTERN(type, array) extern type * near array | 120 | # define EXTERN(type, array) extern type * array |
125 | # define DECLARE(type, array, size) type * near array | 121 | # define DECLARE(type, array, size) type * array |
126 | # define ALLOC(type, array, size) { \ | 122 | # define ALLOC(type, array, size) { \ |
127 | array = (type*)fcalloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \ | 123 | array = (type*)calloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \ |
128 | if (array == NULL) errorMsg("insufficient memory"); \ | 124 | if (array == NULL) errorMsg("insufficient memory"); \ |
129 | } | 125 | } |
130 | # define FREE(array) {if (array != NULL) fcfree(array), array=NULL;} | 126 | # define FREE(array) {if (array != NULL) free(array), array=NULL;} |
131 | #else | 127 | #else |
132 | # define EXTERN(type, array) extern type array[] | 128 | # define EXTERN(type, array) extern type array[] |
133 | # define DECLARE(type, array, size) type array[size] | 129 | # define DECLARE(type, array, size) type array[size] |
@@ -284,55 +280,55 @@ extern int save_orig_name; /* set if original name must be saved */ | |||
284 | 280 | ||
285 | 281 | ||
286 | /* in zip.c: */ | 282 | /* in zip.c: */ |
287 | extern int zip OF((int in, int out)); | 283 | extern int zip (int in, int out); |
288 | extern int file_read OF((char *buf, unsigned size)); | 284 | extern int file_read (char *buf, unsigned size); |
289 | 285 | ||
290 | /* in unzip.c */ | 286 | /* in unzip.c */ |
291 | extern int unzip OF((int in, int out)); | 287 | extern int unzip (int in, int out); |
292 | extern int check_zipfile OF((int in)); | 288 | extern int check_zipfile (int in); |
293 | 289 | ||
294 | /* in unpack.c */ | 290 | /* in unpack.c */ |
295 | extern int unpack OF((int in, int out)); | 291 | extern int unpack (int in, int out); |
296 | 292 | ||
297 | /* in unlzh.c */ | 293 | /* in unlzh.c */ |
298 | extern int unlzh OF((int in, int out)); | 294 | extern int unlzh (int in, int out); |
299 | 295 | ||
300 | /* in gzip.c */ | 296 | /* in gzip.c */ |
301 | RETSIGTYPE abort_gzip OF((void)); | 297 | RETSIGTYPE abort_gzip (void); |
302 | 298 | ||
303 | /* in deflate.c */ | 299 | /* in deflate.c */ |
304 | void lm_init OF((ush * flags)); | 300 | void lm_init (ush * flags); |
305 | ulg deflate OF((void)); | 301 | ulg deflate (void); |
306 | 302 | ||
307 | /* in trees.c */ | 303 | /* in trees.c */ |
308 | void ct_init OF((ush * attr, int *method)); | 304 | void ct_init (ush * attr, int *method); |
309 | int ct_tally OF((int dist, int lc)); | 305 | int ct_tally (int dist, int lc); |
310 | ulg flush_block OF((char *buf, ulg stored_len, int eof)); | 306 | ulg flush_block (char *buf, ulg stored_len, int eof); |
311 | 307 | ||
312 | /* in bits.c */ | 308 | /* in bits.c */ |
313 | void bi_init OF((file_t zipfile)); | 309 | void bi_init (file_t zipfile); |
314 | void send_bits OF((int value, int length)); | 310 | void send_bits (int value, int length); |
315 | unsigned bi_reverse OF((unsigned value, int length)); | 311 | unsigned bi_reverse (unsigned value, int length); |
316 | void bi_windup OF((void)); | 312 | void bi_windup (void); |
317 | void copy_block OF((char *buf, unsigned len, int header)); | 313 | void copy_block (char *buf, unsigned len, int header); |
318 | extern int (*read_buf) OF((char *buf, unsigned size)); | 314 | extern int (*read_buf) (char *buf, unsigned size); |
319 | 315 | ||
320 | /* in util.c: */ | 316 | /* in util.c: */ |
321 | extern int copy OF((int in, int out)); | 317 | extern int copy (int in, int out); |
322 | extern ulg updcrc OF((uch * s, unsigned n)); | 318 | extern ulg updcrc (uch * s, unsigned n); |
323 | extern void clear_bufs OF((void)); | 319 | extern void clear_bufs (void); |
324 | extern int fill_inbuf OF((int eof_ok)); | 320 | extern int fill_inbuf (int eof_ok); |
325 | extern void flush_outbuf OF((void)); | 321 | extern void flush_outbuf (void); |
326 | extern void flush_window OF((void)); | 322 | extern void flush_window (void); |
327 | extern void write_buf OF((int fd, voidp buf, unsigned cnt)); | 323 | extern void write_buf (int fd, void * buf, unsigned cnt); |
328 | extern char *strlwr OF((char *s)); | 324 | extern char *strlwr (char *s); |
329 | extern char *add_envopt OF((int *argcp, char ***argvp, char *env)); | 325 | extern char *add_envopt (int *argcp, char ***argvp, char *env); |
330 | extern void read_error OF((void)); | 326 | extern void read_error (void); |
331 | extern void write_error OF((void)); | 327 | extern void write_error (void); |
332 | extern void display_ratio OF((long num, long den, FILE * file)); | 328 | extern void display_ratio (long num, long den, FILE * file); |
333 | 329 | ||
334 | /* in inflate.c */ | 330 | /* in inflate.c */ |
335 | extern int inflate OF((void)); | 331 | extern int inflate (void); |
336 | 332 | ||
337 | /* lzw.h -- define the lzw functions. | 333 | /* lzw.h -- define the lzw functions. |
338 | * Copyright (C) 1992-1993 Jean-loup Gailly. | 334 | * Copyright (C) 1992-1993 Jean-loup Gailly. |
@@ -795,7 +791,7 @@ local int bi_valid; | |||
795 | * are always zero. | 791 | * are always zero. |
796 | */ | 792 | */ |
797 | 793 | ||
798 | int (*read_buf) OF((char *buf, unsigned size)); | 794 | int (*read_buf) (char *buf, unsigned size); |
799 | 795 | ||
800 | /* Current input function. Set to mem_read for in-memory compression */ | 796 | /* Current input function. Set to mem_read for in-memory compression */ |
801 | 797 | ||
@@ -1148,16 +1144,16 @@ local config configuration_table = | |||
1148 | /* =========================================================================== | 1144 | /* =========================================================================== |
1149 | * Prototypes for local functions. | 1145 | * Prototypes for local functions. |
1150 | */ | 1146 | */ |
1151 | local void fill_window OF((void)); | 1147 | local void fill_window (void); |
1152 | 1148 | ||
1153 | int longest_match OF((IPos cur_match)); | 1149 | int longest_match (IPos cur_match); |
1154 | 1150 | ||
1155 | #ifdef ASMV | 1151 | #ifdef ASMV |
1156 | void match_init OF((void)); /* asm code initialization */ | 1152 | void match_init (void); /* asm code initialization */ |
1157 | #endif | 1153 | #endif |
1158 | 1154 | ||
1159 | #ifdef DEBUG | 1155 | #ifdef DEBUG |
1160 | local void check_match OF((IPos start, IPos match, int length)); | 1156 | local void check_match (IPos start, IPos match, int length); |
1161 | #endif | 1157 | #endif |
1162 | 1158 | ||
1163 | /* =========================================================================== | 1159 | /* =========================================================================== |
@@ -1708,7 +1704,7 @@ struct utimbuf { | |||
1708 | # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) | 1704 | # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) |
1709 | #endif | 1705 | #endif |
1710 | 1706 | ||
1711 | typedef RETSIGTYPE(*sig_type) OF((int)); | 1707 | typedef RETSIGTYPE(*sig_type) (int); |
1712 | 1708 | ||
1713 | #ifndef O_BINARY | 1709 | #ifndef O_BINARY |
1714 | # define O_BINARY 0 /* creation mode for open() */ | 1710 | # define O_BINARY 0 /* creation mode for open() */ |
@@ -1743,7 +1739,7 @@ typedef RETSIGTYPE(*sig_type) OF((int)); | |||
1743 | 1739 | ||
1744 | #ifdef NO_OFF_T | 1740 | #ifdef NO_OFF_T |
1745 | typedef long off_t; | 1741 | typedef long off_t; |
1746 | off_t lseek OF((int fd, off_t offset, int whence)); | 1742 | off_t lseek (int fd, off_t offset, int whence); |
1747 | #endif | 1743 | #endif |
1748 | 1744 | ||
1749 | /* Separator for file name parts (see shorten_name()) */ | 1745 | /* Separator for file name parts (see shorten_name()) */ |
@@ -2246,17 +2242,17 @@ extern unsigned near strstart; /* window offset of current string */ | |||
2246 | * Local (static) routines in this file. | 2242 | * Local (static) routines in this file. |
2247 | */ | 2243 | */ |
2248 | 2244 | ||
2249 | local void init_block OF((void)); | 2245 | local void init_block (void); |
2250 | local void pqdownheap OF((ct_data near * tree, int k)); | 2246 | local void pqdownheap (ct_data near * tree, int k); |
2251 | local void gen_bitlen OF((tree_desc near * desc)); | 2247 | local void gen_bitlen (tree_desc near * desc); |
2252 | local void gen_codes OF((ct_data near * tree, int max_code)); | 2248 | local void gen_codes (ct_data near * tree, int max_code); |
2253 | local void build_tree OF((tree_desc near * desc)); | 2249 | local void build_tree (tree_desc near * desc); |
2254 | local void scan_tree OF((ct_data near * tree, int max_code)); | 2250 | local void scan_tree (ct_data near * tree, int max_code); |
2255 | local void send_tree OF((ct_data near * tree, int max_code)); | 2251 | local void send_tree (ct_data near * tree, int max_code); |
2256 | local int build_bl_tree OF((void)); | 2252 | local int build_bl_tree (void); |
2257 | local void send_all_trees OF((int lcodes, int dcodes, int blcodes)); | 2253 | local void send_all_trees (int lcodes, int dcodes, int blcodes); |
2258 | local void compress_block OF((ct_data near * ltree, ct_data near * dtree)); | 2254 | local void compress_block (ct_data near * ltree, ct_data near * dtree); |
2259 | local void set_file_type OF((void)); | 2255 | local void set_file_type (void); |
2260 | 2256 | ||
2261 | 2257 | ||
2262 | #ifndef DEBUG | 2258 | #ifndef DEBUG |
@@ -3161,12 +3157,8 @@ char *s; | |||
3161 | 3157 | ||
3162 | /* Provide missing strspn and strcspn functions. */ | 3158 | /* Provide missing strspn and strcspn functions. */ |
3163 | 3159 | ||
3164 | # ifndef __STDC__ | 3160 | int strspn (const char *s, const char *accept); |
3165 | # define const | 3161 | int strcspn (const char *s, const char *reject); |
3166 | # endif | ||
3167 | |||
3168 | int strspn OF((const char *s, const char *accept)); | ||
3169 | int strcspn OF((const char *s, const char *reject)); | ||
3170 | 3162 | ||
3171 | /* ======================================================================== | 3163 | /* ======================================================================== |
3172 | * Return the length of the maximum initial segment | 3164 | * Return the length of the maximum initial segment |
@@ -3398,4 +3390,3 @@ unsigned size; | |||
3398 | isize += (ulg) len; | 3390 | isize += (ulg) len; |
3399 | return (int) len; | 3391 | return (int) len; |
3400 | } | 3392 | } |
3401 | #endif | ||