diff options
Diffstat (limited to 'archival')
-rw-r--r-- | archival/libunarchive/decompress_unzip.c | 87 |
1 files changed, 24 insertions, 63 deletions
diff --git a/archival/libunarchive/decompress_unzip.c b/archival/libunarchive/decompress_unzip.c index a589bdcd4..e39901c1b 100644 --- a/archival/libunarchive/decompress_unzip.c +++ b/archival/libunarchive/decompress_unzip.c | |||
@@ -21,21 +21,6 @@ | |||
21 | * to free leaked bytebuffer memory (used in unzip.c), and some minor style | 21 | * to free leaked bytebuffer memory (used in unzip.c), and some minor style |
22 | * guide cleanups by Ed Clark | 22 | * guide cleanups by Ed Clark |
23 | * | 23 | * |
24 | * This program is free software; you can redistribute it and/or modify | ||
25 | * it under the terms of the GNU General Public License as published by | ||
26 | * the Free Software Foundation; either version 2 of the License, or | ||
27 | * (at your option) any later version. | ||
28 | * | ||
29 | * This program is distributed in the hope that it will be useful, | ||
30 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
31 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
32 | * General Public License for more details. | ||
33 | * | ||
34 | * You should have received a copy of the GNU General Public License | ||
35 | * along with this program; if not, write to the Free Software | ||
36 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
37 | * | ||
38 | * | ||
39 | * gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface | 24 | * gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface |
40 | * Copyright (C) 1992-1993 Jean-loup Gailly | 25 | * Copyright (C) 1992-1993 Jean-loup Gailly |
41 | * The unzip code was written and put in the public domain by Mark Adler. | 26 | * The unzip code was written and put in the public domain by Mark Adler. |
@@ -43,38 +28,14 @@ | |||
43 | * written by Spencer Thomas, Joe Orost, James Woods, Jim McKie, Steve Davies, | 28 | * written by Spencer Thomas, Joe Orost, James Woods, Jim McKie, Steve Davies, |
44 | * Ken Turkowski, Dave Mack and Peter Jannesen. | 29 | * Ken Turkowski, Dave Mack and Peter Jannesen. |
45 | * | 30 | * |
46 | * See the license_msg below and the file COPYING for the software license. | ||
47 | * See the file algorithm.doc for the compression algorithms and file formats. | 31 | * See the file algorithm.doc for the compression algorithms and file formats. |
32 | * | ||
33 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | ||
48 | */ | 34 | */ |
49 | 35 | ||
50 | #if 0 | 36 | #include "libbb.h" |
51 | static char *license_msg[] = { | ||
52 | " Copyright (C) 1992-1993 Jean-loup Gailly", | ||
53 | " This program is free software; you can redistribute it and/or modify", | ||
54 | " it under the terms of the GNU General Public License as published by", | ||
55 | " the Free Software Foundation; either version 2, or (at your option)", | ||
56 | " any later version.", | ||
57 | "", | ||
58 | " This program is distributed in the hope that it will be useful,", | ||
59 | " but WITHOUT ANY WARRANTY; without even the implied warranty of", | ||
60 | " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the", | ||
61 | " GNU General Public License for more details.", | ||
62 | "", | ||
63 | " You should have received a copy of the GNU General Public License", | ||
64 | " along with this program; if not, write to the Free Software", | ||
65 | " Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.", | ||
66 | 0 | ||
67 | }; | ||
68 | #endif | ||
69 | |||
70 | #include <sys/types.h> | ||
71 | #include <sys/wait.h> | 37 | #include <sys/wait.h> |
72 | #include <signal.h> | 38 | #include <signal.h> |
73 | #include <stdlib.h> | ||
74 | #include <string.h> | ||
75 | #include <unistd.h> | ||
76 | #include <fcntl.h> | ||
77 | #include "libbb.h" | ||
78 | #include "unarchive.h" | 39 | #include "unarchive.h" |
79 | 40 | ||
80 | typedef struct huft_s { | 41 | typedef struct huft_s { |
@@ -213,17 +174,17 @@ int huft_build(unsigned int *b, const unsigned int n, | |||
213 | unsigned eob_len; /* length of end-of-block code (value 256) */ | 174 | unsigned eob_len; /* length of end-of-block code (value 256) */ |
214 | unsigned f; /* i repeats in table every f entries */ | 175 | unsigned f; /* i repeats in table every f entries */ |
215 | int g; /* maximum code length */ | 176 | int g; /* maximum code length */ |
216 | int h; /* table level */ | 177 | int htl; /* table level */ |
217 | register unsigned i; /* counter, current code */ | 178 | unsigned i; /* counter, current code */ |
218 | register unsigned j; /* counter */ | 179 | unsigned j; /* counter */ |
219 | register int k; /* number of bits in current code */ | 180 | int k; /* number of bits in current code */ |
220 | register unsigned *p; /* pointer into c[], b[], or v[] */ | 181 | unsigned *p; /* pointer into c[], b[], or v[] */ |
221 | register huft_t *q; /* points to current table */ | 182 | huft_t *q; /* points to current table */ |
222 | huft_t r; /* table entry for structure assignment */ | 183 | huft_t r; /* table entry for structure assignment */ |
223 | huft_t *u[BMAX]; /* table stack */ | 184 | huft_t *u[BMAX]; /* table stack */ |
224 | unsigned v[N_MAX]; /* values in order of bit length */ | 185 | unsigned v[N_MAX]; /* values in order of bit length */ |
225 | int ws[BMAX+1]; /* bits decoded stack */ | 186 | int ws[BMAX+1]; /* bits decoded stack */ |
226 | register int w; /* bits decoded */ | 187 | int w; /* bits decoded */ |
227 | unsigned x[BMAX + 1]; /* bit offsets, then code stack */ | 188 | unsigned x[BMAX + 1]; /* bit offsets, then code stack */ |
228 | unsigned *xp; /* pointer into x */ | 189 | unsigned *xp; /* pointer into x */ |
229 | int y; /* number of dummy codes added */ | 190 | int y; /* number of dummy codes added */ |
@@ -284,7 +245,7 @@ int huft_build(unsigned int *b, const unsigned int n, | |||
284 | /* Generate the Huffman codes and for each, make the table entries */ | 245 | /* Generate the Huffman codes and for each, make the table entries */ |
285 | x[0] = i = 0; /* first Huffman code is zero */ | 246 | x[0] = i = 0; /* first Huffman code is zero */ |
286 | p = v; /* grab values in bit order */ | 247 | p = v; /* grab values in bit order */ |
287 | h = -1; /* no tables yet--level -1 */ | 248 | htl = -1; /* no tables yet--level -1 */ |
288 | w = ws[0] = 0; /* bits decoded */ | 249 | w = ws[0] = 0; /* bits decoded */ |
289 | u[0] = (huft_t *) NULL; /* just to keep compilers happy */ | 250 | u[0] = (huft_t *) NULL; /* just to keep compilers happy */ |
290 | q = (huft_t *) NULL; /* ditto */ | 251 | q = (huft_t *) NULL; /* ditto */ |
@@ -296,8 +257,8 @@ int huft_build(unsigned int *b, const unsigned int n, | |||
296 | while (a--) { | 257 | while (a--) { |
297 | /* here i is the Huffman code of length k bits for value *p */ | 258 | /* here i is the Huffman code of length k bits for value *p */ |
298 | /* make tables up to required level */ | 259 | /* make tables up to required level */ |
299 | while (k > ws[h + 1]) { | 260 | while (k > ws[htl + 1]) { |
300 | w = ws[++h]; | 261 | w = ws[++htl]; |
301 | 262 | ||
302 | /* compute minimum size table less than or equal to *m bits */ | 263 | /* compute minimum size table less than or equal to *m bits */ |
303 | z = (z = g - w) > *m ? *m : z; /* upper limit on table size */ | 264 | z = (z = g - w) > *m ? *m : z; /* upper limit on table size */ |
@@ -314,22 +275,22 @@ int huft_build(unsigned int *b, const unsigned int n, | |||
314 | } | 275 | } |
315 | j = (w + j > eob_len && w < eob_len) ? eob_len - w : j; /* make EOB code end at table */ | 276 | j = (w + j > eob_len && w < eob_len) ? eob_len - w : j; /* make EOB code end at table */ |
316 | z = 1 << j; /* table entries for j-bit table */ | 277 | z = 1 << j; /* table entries for j-bit table */ |
317 | ws[h+1] = w + j; /* set bits decoded in stack */ | 278 | ws[htl+1] = w + j; /* set bits decoded in stack */ |
318 | 279 | ||
319 | /* allocate and link in new table */ | 280 | /* allocate and link in new table */ |
320 | q = (huft_t *) xmalloc((z + 1) * sizeof(huft_t)); | 281 | q = (huft_t *) xzalloc((z + 1) * sizeof(huft_t)); |
321 | *t = q + 1; /* link to list for huft_free() */ | 282 | *t = q + 1; /* link to list for huft_free() */ |
322 | *(t = &(q->v.t)) = NULL; | 283 | t = &(q->v.t); |
323 | u[h] = ++q; /* table starts after link */ | 284 | u[htl] = ++q; /* table starts after link */ |
324 | 285 | ||
325 | /* connect to last table, if there is one */ | 286 | /* connect to last table, if there is one */ |
326 | if (h) { | 287 | if (htl) { |
327 | x[h] = i; /* save pattern for backing up */ | 288 | x[htl] = i; /* save pattern for backing up */ |
328 | r.b = (unsigned char) (w - ws[h - 1]); /* bits to dump before this table */ | 289 | r.b = (unsigned char) (w - ws[htl - 1]); /* bits to dump before this table */ |
329 | r.e = (unsigned char) (16 + j); /* bits in this table */ | 290 | r.e = (unsigned char) (16 + j); /* bits in this table */ |
330 | r.v.t = q; /* pointer to this table */ | 291 | r.v.t = q; /* pointer to this table */ |
331 | j = (i & ((1 << w) - 1)) >> ws[h - 1]; | 292 | j = (i & ((1 << w) - 1)) >> ws[htl - 1]; |
332 | u[h - 1][j] = r; /* connect to last table */ | 293 | u[htl - 1][j] = r; /* connect to last table */ |
333 | } | 294 | } |
334 | } | 295 | } |
335 | 296 | ||
@@ -358,8 +319,8 @@ int huft_build(unsigned int *b, const unsigned int n, | |||
358 | i ^= j; | 319 | i ^= j; |
359 | 320 | ||
360 | /* backup over finished tables */ | 321 | /* backup over finished tables */ |
361 | while ((i & ((1 << w) - 1)) != x[h]) { | 322 | while ((i & ((1 << w) - 1)) != x[htl]) { |
362 | w = ws[--h]; | 323 | w = ws[--htl]; |
363 | } | 324 | } |
364 | } | 325 | } |
365 | } | 326 | } |