aboutsummaryrefslogtreecommitdiff
path: root/gzip.c
diff options
context:
space:
mode:
Diffstat (limited to 'gzip.c')
-rw-r--r--gzip.c191
1 files changed, 91 insertions, 100 deletions
diff --git a/gzip.c b/gzip.c
index 0a969d8db..55ec5bc4e 100644
--- a/gzip.c
+++ b/gzip.c
@@ -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
15static const char gzip_usage[] = 41static 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__
37typedef void *voidp;
38#else
39typedef 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: */
287extern int zip OF((int in, int out)); 283extern int zip (int in, int out);
288extern int file_read OF((char *buf, unsigned size)); 284extern int file_read (char *buf, unsigned size);
289 285
290 /* in unzip.c */ 286 /* in unzip.c */
291extern int unzip OF((int in, int out)); 287extern int unzip (int in, int out);
292extern int check_zipfile OF((int in)); 288extern int check_zipfile (int in);
293 289
294 /* in unpack.c */ 290 /* in unpack.c */
295extern int unpack OF((int in, int out)); 291extern int unpack (int in, int out);
296 292
297 /* in unlzh.c */ 293 /* in unlzh.c */
298extern int unlzh OF((int in, int out)); 294extern int unlzh (int in, int out);
299 295
300 /* in gzip.c */ 296 /* in gzip.c */
301RETSIGTYPE abort_gzip OF((void)); 297RETSIGTYPE abort_gzip (void);
302 298
303 /* in deflate.c */ 299 /* in deflate.c */
304void lm_init OF((ush * flags)); 300void lm_init (ush * flags);
305ulg deflate OF((void)); 301ulg deflate (void);
306 302
307 /* in trees.c */ 303 /* in trees.c */
308void ct_init OF((ush * attr, int *method)); 304void ct_init (ush * attr, int *method);
309int ct_tally OF((int dist, int lc)); 305int ct_tally (int dist, int lc);
310ulg flush_block OF((char *buf, ulg stored_len, int eof)); 306ulg flush_block (char *buf, ulg stored_len, int eof);
311 307
312 /* in bits.c */ 308 /* in bits.c */
313void bi_init OF((file_t zipfile)); 309void bi_init (file_t zipfile);
314void send_bits OF((int value, int length)); 310void send_bits (int value, int length);
315unsigned bi_reverse OF((unsigned value, int length)); 311unsigned bi_reverse (unsigned value, int length);
316void bi_windup OF((void)); 312void bi_windup (void);
317void copy_block OF((char *buf, unsigned len, int header)); 313void copy_block (char *buf, unsigned len, int header);
318extern int (*read_buf) OF((char *buf, unsigned size)); 314extern int (*read_buf) (char *buf, unsigned size);
319 315
320 /* in util.c: */ 316 /* in util.c: */
321extern int copy OF((int in, int out)); 317extern int copy (int in, int out);
322extern ulg updcrc OF((uch * s, unsigned n)); 318extern ulg updcrc (uch * s, unsigned n);
323extern void clear_bufs OF((void)); 319extern void clear_bufs (void);
324extern int fill_inbuf OF((int eof_ok)); 320extern int fill_inbuf (int eof_ok);
325extern void flush_outbuf OF((void)); 321extern void flush_outbuf (void);
326extern void flush_window OF((void)); 322extern void flush_window (void);
327extern void write_buf OF((int fd, voidp buf, unsigned cnt)); 323extern void write_buf (int fd, void * buf, unsigned cnt);
328extern char *strlwr OF((char *s)); 324extern char *strlwr (char *s);
329extern char *add_envopt OF((int *argcp, char ***argvp, char *env)); 325extern char *add_envopt (int *argcp, char ***argvp, char *env);
330extern void read_error OF((void)); 326extern void read_error (void);
331extern void write_error OF((void)); 327extern void write_error (void);
332extern void display_ratio OF((long num, long den, FILE * file)); 328extern void display_ratio (long num, long den, FILE * file);
333 329
334 /* in inflate.c */ 330 /* in inflate.c */
335extern int inflate OF((void)); 331extern 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
798int (*read_buf) OF((char *buf, unsigned size)); 794int (*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 */
1151local void fill_window OF((void)); 1147local void fill_window (void);
1152 1148
1153int longest_match OF((IPos cur_match)); 1149int longest_match (IPos cur_match);
1154 1150
1155#ifdef ASMV 1151#ifdef ASMV
1156void match_init OF((void)); /* asm code initialization */ 1152void match_init (void); /* asm code initialization */
1157#endif 1153#endif
1158 1154
1159#ifdef DEBUG 1155#ifdef DEBUG
1160local void check_match OF((IPos start, IPos match, int length)); 1156local 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
1711typedef RETSIGTYPE(*sig_type) OF((int)); 1707typedef 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
1745typedef long off_t; 1741typedef long off_t;
1746off_t lseek OF((int fd, off_t offset, int whence)); 1742off_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
2249local void init_block OF((void)); 2245local void init_block (void);
2250local void pqdownheap OF((ct_data near * tree, int k)); 2246local void pqdownheap (ct_data near * tree, int k);
2251local void gen_bitlen OF((tree_desc near * desc)); 2247local void gen_bitlen (tree_desc near * desc);
2252local void gen_codes OF((ct_data near * tree, int max_code)); 2248local void gen_codes (ct_data near * tree, int max_code);
2253local void build_tree OF((tree_desc near * desc)); 2249local void build_tree (tree_desc near * desc);
2254local void scan_tree OF((ct_data near * tree, int max_code)); 2250local void scan_tree (ct_data near * tree, int max_code);
2255local void send_tree OF((ct_data near * tree, int max_code)); 2251local void send_tree (ct_data near * tree, int max_code);
2256local int build_bl_tree OF((void)); 2252local int build_bl_tree (void);
2257local void send_all_trees OF((int lcodes, int dcodes, int blcodes)); 2253local void send_all_trees (int lcodes, int dcodes, int blcodes);
2258local void compress_block OF((ct_data near * ltree, ct_data near * dtree)); 2254local void compress_block (ct_data near * ltree, ct_data near * dtree);
2259local void set_file_type OF((void)); 2255local 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__ 3160int strspn (const char *s, const char *accept);
3165# define const 3161int strcspn (const char *s, const char *reject);
3166# endif
3167
3168int strspn OF((const char *s, const char *accept));
3169int 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