diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-08-22 04:15:47 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-08-22 04:15:47 +0000 |
commit | 39eb040757c9025f18866741ff3de9e2a1aaa0fc (patch) | |
tree | 1fd48243f4ce204326f01f83dd5270e1b4af0b4b | |
parent | a07c9026486043359b84a16576cccc635075c300 (diff) | |
download | busybox-w32-39eb040757c9025f18866741ff3de9e2a1aaa0fc.tar.gz busybox-w32-39eb040757c9025f18866741ff3de9e2a1aaa0fc.tar.bz2 busybox-w32-39eb040757c9025f18866741ff3de9e2a1aaa0fc.zip |
Patch from Rodney Brown <RDBrown@mira.net>, shrinking 1.5k
from gzip by careful optimization. Appears to work just fine
(I've tested the changes on x86, ARM, and powerpc).
-rw-r--r-- | Changelog | 21 | ||||
-rw-r--r-- | archival/gzip.c | 72 | ||||
-rw-r--r-- | gzip.c | 72 |
3 files changed, 111 insertions, 54 deletions
@@ -1,3 +1,24 @@ | |||
1 | 0.61.pre | ||
2 | |||
3 | Development Version | ||
4 | |||
5 | |||
6 | |||
7 | New Applets: | ||
8 | * Erik Andersen -- Merged several applets from tinylogin, | ||
9 | namely adduser, addgroup, deluser, delgroup, getty. | ||
10 | |||
11 | |||
12 | Other Changes: | ||
13 | |||
14 | * Rodney Brown <RDBrown@mira.net> | ||
15 | -- Optimized gzip.c, shrinking it be ~1.5k | ||
16 | |||
17 | -Erik Andersen, --not yet released-- | ||
18 | |||
19 | |||
20 | |||
21 | |||
1 | 0.60.0 | 22 | 0.60.0 |
2 | 23 | ||
3 | Note: | 24 | Note: |
diff --git a/archival/gzip.c b/archival/gzip.c index 54bb72745..53646df7c 100644 --- a/archival/gzip.c +++ b/archival/gzip.c | |||
@@ -110,8 +110,7 @@ static int method; /* compression method */ | |||
110 | #ifdef DYN_ALLOC | 110 | #ifdef DYN_ALLOC |
111 | # define DECLARE(type, array, size) static type * array | 111 | # define DECLARE(type, array, size) static type * array |
112 | # define ALLOC(type, array, size) { \ | 112 | # define ALLOC(type, array, size) { \ |
113 | array = (type*)calloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \ | 113 | array = (type*)xcalloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \ |
114 | if (array == NULL) error_msg(memory_exhausted); \ | ||
115 | } | 114 | } |
116 | # define FREE(array) {if (array != NULL) free(array), array=NULL;} | 115 | # define FREE(array) {if (array != NULL) free(array), array=NULL;} |
117 | #else | 116 | #else |
@@ -181,16 +180,17 @@ typedef int file_t; /* Do not use stdio */ | |||
181 | outbuf[outcnt++] = (uch) ((w) & 0xff); \ | 180 | outbuf[outcnt++] = (uch) ((w) & 0xff); \ |
182 | outbuf[outcnt++] = (uch) ((ush)(w) >> 8); \ | 181 | outbuf[outcnt++] = (uch) ((ush)(w) >> 8); \ |
183 | } else { \ | 182 | } else { \ |
184 | put_byte((uch)((w) & 0xff)); \ | 183 | put_short_when_full(w); \ |
185 | put_byte((uch)((ush)(w) >> 8)); \ | ||
186 | } \ | 184 | } \ |
187 | } | 185 | } |
188 | 186 | ||
189 | /* Output a 32 bit value to the bit stream, lsb first */ | 187 | /* Output a 32 bit value to the bit stream, lsb first */ |
188 | #if 0 | ||
190 | #define put_long(n) { \ | 189 | #define put_long(n) { \ |
191 | put_short((n) & 0xffff); \ | 190 | put_short((n) & 0xffff); \ |
192 | put_short(((ulg)(n)) >> 16); \ | 191 | put_short(((ulg)(n)) >> 16); \ |
193 | } | 192 | } |
193 | #endif | ||
194 | 194 | ||
195 | #define seekable() 0 /* force sequential output */ | 195 | #define seekable() 0 /* force sequential output */ |
196 | #define translate_eol 0 /* no option -a yet */ | 196 | #define translate_eol 0 /* no option -a yet */ |
@@ -220,7 +220,6 @@ typedef int file_t; /* Do not use stdio */ | |||
220 | #endif | 220 | #endif |
221 | 221 | ||
222 | 222 | ||
223 | |||
224 | /* from zip.c: */ | 223 | /* from zip.c: */ |
225 | static int zip (int in, int out); | 224 | static int zip (int in, int out); |
226 | static int file_read (char *buf, unsigned size); | 225 | static int file_read (char *buf, unsigned size); |
@@ -248,6 +247,9 @@ static int (*read_buf) (char *buf, unsigned size); | |||
248 | /* from util.c: */ | 247 | /* from util.c: */ |
249 | static void flush_outbuf (void); | 248 | static void flush_outbuf (void); |
250 | 249 | ||
250 | static void put_short_when_full (ush); | ||
251 | |||
252 | |||
251 | /* lzw.h -- define the lzw functions. | 253 | /* lzw.h -- define the lzw functions. |
252 | * Copyright (C) 1992-1993 Jean-loup Gailly. | 254 | * Copyright (C) 1992-1993 Jean-loup Gailly. |
253 | * This is free software; you can redistribute it and/or modify it under the | 255 | * This is free software; you can redistribute it and/or modify it under the |
@@ -388,18 +390,11 @@ static ulg updcrc(uch *s, unsigned n) | |||
388 | static unsigned long crc_32_tab[256]; | 390 | static unsigned long crc_32_tab[256]; |
389 | if (crc_table_empty) { | 391 | if (crc_table_empty) { |
390 | unsigned long csr; /* crc shift register */ | 392 | unsigned long csr; /* crc shift register */ |
391 | unsigned long e=0; /* polynomial exclusive-or pattern */ | 393 | const unsigned long e = 0xedb88320L; /* polynomial exclusive-or pattern */ |
392 | int i; /* counter for all possible eight bit values */ | 394 | int i; /* counter for all possible eight bit values */ |
393 | int k; /* byte being shifted into crc apparatus */ | 395 | int k; /* byte being shifted into crc apparatus */ |
394 | 396 | ||
395 | /* terms of polynomial defining this crc (except x^32): */ | 397 | /* Compute table of CRC's. */ |
396 | static const int p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; | ||
397 | |||
398 | /* Make exclusive-or pattern from polynomial (0xedb88320) */ | ||
399 | for (i = 0; i < sizeof(p)/sizeof(int); i++) | ||
400 | e |= 1L << (31 - p[i]); | ||
401 | |||
402 | /* Compute and print table of CRC's, five per line */ | ||
403 | crc_32_tab[0] = 0x00000000L; | 398 | crc_32_tab[0] = 0x00000000L; |
404 | for (i = 1; i < 256; i++) { | 399 | for (i = 1; i < 256; i++) { |
405 | csr = i; | 400 | csr = i; |
@@ -1206,7 +1201,6 @@ typedef struct dirent dir_type; | |||
1206 | 1201 | ||
1207 | typedef RETSIGTYPE(*sig_type) (int); | 1202 | typedef RETSIGTYPE(*sig_type) (int); |
1208 | 1203 | ||
1209 | |||
1210 | /* ======================================================================== */ | 1204 | /* ======================================================================== */ |
1211 | // int main (argc, argv) | 1205 | // int main (argc, argv) |
1212 | // int argc; | 1206 | // int argc; |
@@ -1291,11 +1285,9 @@ int gzip_main(int argc, char **argv) | |||
1291 | 1285 | ||
1292 | /* Open input file */ | 1286 | /* Open input file */ |
1293 | inFileNum = open(ifname, O_RDONLY); | 1287 | inFileNum = open(ifname, O_RDONLY); |
1294 | if (inFileNum < 0) | 1288 | if (inFileNum < 0 || stat(ifname, &statBuf) < 0) |
1295 | perror_msg_and_die("%s", ifname); | 1289 | perror_msg_and_die("%s", ifname); |
1296 | /* Get the time stamp on the input file. */ | 1290 | /* Get the time stamp on the input file. */ |
1297 | if (stat(ifname, &statBuf) < 0) | ||
1298 | perror_msg_and_die("%s", ifname); | ||
1299 | time_stamp = statBuf.st_ctime; | 1291 | time_stamp = statBuf.st_ctime; |
1300 | ifile_size = statBuf.st_size; | 1292 | ifile_size = statBuf.st_size; |
1301 | } | 1293 | } |
@@ -1433,16 +1425,20 @@ int gzip_main(int argc, char **argv) | |||
1433 | #define BL_CODES 19 | 1425 | #define BL_CODES 19 |
1434 | /* number of codes used to transfer the bit lengths */ | 1426 | /* number of codes used to transfer the bit lengths */ |
1435 | 1427 | ||
1428 | typedef uch extra_bits_t; | ||
1436 | 1429 | ||
1437 | static const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */ | 1430 | /* extra bits for each length code */ |
1431 | static const extra_bits_t extra_lbits[LENGTH_CODES] | ||
1438 | = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, | 1432 | = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, |
1439 | 4, 4, 5, 5, 5, 5, 0 }; | 1433 | 4, 4, 5, 5, 5, 5, 0 }; |
1440 | 1434 | ||
1441 | static const int extra_dbits[D_CODES] /* extra bits for each distance code */ | 1435 | /* extra bits for each distance code */ |
1436 | static const extra_bits_t extra_dbits[D_CODES] | ||
1442 | = { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, | 1437 | = { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, |
1443 | 10, 10, 11, 11, 12, 12, 13, 13 }; | 1438 | 10, 10, 11, 11, 12, 12, 13, 13 }; |
1444 | 1439 | ||
1445 | static const int extra_blbits[BL_CODES] /* extra bits for each bit length code */ | 1440 | /* extra bits for each bit length code */ |
1441 | static const extra_bits_t extra_blbits[BL_CODES] | ||
1446 | = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7 }; | 1442 | = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7 }; |
1447 | 1443 | ||
1448 | #define STORED_BLOCK 0 | 1444 | #define STORED_BLOCK 0 |
@@ -1537,7 +1533,7 @@ static ct_data bl_tree[2 * BL_CODES + 1]; | |||
1537 | typedef struct tree_desc { | 1533 | typedef struct tree_desc { |
1538 | ct_data *dyn_tree; /* the dynamic tree */ | 1534 | ct_data *dyn_tree; /* the dynamic tree */ |
1539 | ct_data *static_tree; /* corresponding static tree or NULL */ | 1535 | ct_data *static_tree; /* corresponding static tree or NULL */ |
1540 | const int *extra_bits; /* extra bits for each code or NULL */ | 1536 | const extra_bits_t *extra_bits; /* extra bits for each code or NULL */ |
1541 | int extra_base; /* base index for extra_bits */ | 1537 | int extra_base; /* base index for extra_bits */ |
1542 | int elems; /* max number of elements in the tree */ | 1538 | int elems; /* max number of elements in the tree */ |
1543 | int max_length; /* max bit length for the codes */ | 1539 | int max_length; /* max bit length for the codes */ |
@@ -1834,7 +1830,7 @@ static void pqdownheap(ct_data *tree, int k) | |||
1834 | static void gen_bitlen(tree_desc *desc) | 1830 | static void gen_bitlen(tree_desc *desc) |
1835 | { | 1831 | { |
1836 | ct_data *tree = desc->dyn_tree; | 1832 | ct_data *tree = desc->dyn_tree; |
1837 | const int *extra = desc->extra_bits; | 1833 | const extra_bits_t *extra = desc->extra_bits; |
1838 | int base = desc->extra_base; | 1834 | int base = desc->extra_base; |
1839 | int max_code = desc->max_code; | 1835 | int max_code = desc->max_code; |
1840 | int max_length = desc->max_length; | 1836 | int max_length = desc->max_length; |
@@ -2466,6 +2462,28 @@ static void set_file_type() | |||
2466 | static ulg crc; /* crc on uncompressed file data */ | 2462 | static ulg crc; /* crc on uncompressed file data */ |
2467 | static long header_bytes; /* number of bytes in gzip header */ | 2463 | static long header_bytes; /* number of bytes in gzip header */ |
2468 | 2464 | ||
2465 | static void put_short_when_full(ush w) | ||
2466 | { | ||
2467 | put_byte((uch)((w) & 0xff)); | ||
2468 | put_byte((uch)((ush)(w) >> 8)); | ||
2469 | } | ||
2470 | |||
2471 | static void put_short_function(ush n) | ||
2472 | { | ||
2473 | put_short(n); | ||
2474 | } | ||
2475 | |||
2476 | static void put_long(ulg n) | ||
2477 | { | ||
2478 | put_short_function((n) & 0xffff); | ||
2479 | put_short_function(((ulg)(n)) >> 16); | ||
2480 | } | ||
2481 | |||
2482 | /* put_header_byte is used for the compressed output | ||
2483 | * - for the initial 4 bytes that can't overflow the buffer. | ||
2484 | */ | ||
2485 | #define put_header_byte(c) {outbuf[outcnt++]=(uch)(c);} | ||
2486 | |||
2469 | /* =========================================================================== | 2487 | /* =========================================================================== |
2470 | * Deflate in to out. | 2488 | * Deflate in to out. |
2471 | * IN assertions: the input and output buffers are cleared. | 2489 | * IN assertions: the input and output buffers are cleared. |
@@ -2485,11 +2503,11 @@ static int zip(int in, int out) | |||
2485 | 2503 | ||
2486 | 2504 | ||
2487 | method = DEFLATED; | 2505 | method = DEFLATED; |
2488 | put_byte(GZIP_MAGIC[0]); /* magic header */ | 2506 | put_header_byte(GZIP_MAGIC[0]); /* magic header */ |
2489 | put_byte(GZIP_MAGIC[1]); | 2507 | put_header_byte(GZIP_MAGIC[1]); |
2490 | put_byte(DEFLATED); /* compression method */ | 2508 | put_header_byte(DEFLATED); /* compression method */ |
2491 | 2509 | ||
2492 | put_byte(my_flags); /* general flags */ | 2510 | put_header_byte(my_flags); /* general flags */ |
2493 | put_long(time_stamp); | 2511 | put_long(time_stamp); |
2494 | 2512 | ||
2495 | /* Write deflated file to zip file */ | 2513 | /* Write deflated file to zip file */ |
@@ -110,8 +110,7 @@ static int method; /* compression method */ | |||
110 | #ifdef DYN_ALLOC | 110 | #ifdef DYN_ALLOC |
111 | # define DECLARE(type, array, size) static type * array | 111 | # define DECLARE(type, array, size) static type * array |
112 | # define ALLOC(type, array, size) { \ | 112 | # define ALLOC(type, array, size) { \ |
113 | array = (type*)calloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \ | 113 | array = (type*)xcalloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \ |
114 | if (array == NULL) error_msg(memory_exhausted); \ | ||
115 | } | 114 | } |
116 | # define FREE(array) {if (array != NULL) free(array), array=NULL;} | 115 | # define FREE(array) {if (array != NULL) free(array), array=NULL;} |
117 | #else | 116 | #else |
@@ -181,16 +180,17 @@ typedef int file_t; /* Do not use stdio */ | |||
181 | outbuf[outcnt++] = (uch) ((w) & 0xff); \ | 180 | outbuf[outcnt++] = (uch) ((w) & 0xff); \ |
182 | outbuf[outcnt++] = (uch) ((ush)(w) >> 8); \ | 181 | outbuf[outcnt++] = (uch) ((ush)(w) >> 8); \ |
183 | } else { \ | 182 | } else { \ |
184 | put_byte((uch)((w) & 0xff)); \ | 183 | put_short_when_full(w); \ |
185 | put_byte((uch)((ush)(w) >> 8)); \ | ||
186 | } \ | 184 | } \ |
187 | } | 185 | } |
188 | 186 | ||
189 | /* Output a 32 bit value to the bit stream, lsb first */ | 187 | /* Output a 32 bit value to the bit stream, lsb first */ |
188 | #if 0 | ||
190 | #define put_long(n) { \ | 189 | #define put_long(n) { \ |
191 | put_short((n) & 0xffff); \ | 190 | put_short((n) & 0xffff); \ |
192 | put_short(((ulg)(n)) >> 16); \ | 191 | put_short(((ulg)(n)) >> 16); \ |
193 | } | 192 | } |
193 | #endif | ||
194 | 194 | ||
195 | #define seekable() 0 /* force sequential output */ | 195 | #define seekable() 0 /* force sequential output */ |
196 | #define translate_eol 0 /* no option -a yet */ | 196 | #define translate_eol 0 /* no option -a yet */ |
@@ -220,7 +220,6 @@ typedef int file_t; /* Do not use stdio */ | |||
220 | #endif | 220 | #endif |
221 | 221 | ||
222 | 222 | ||
223 | |||
224 | /* from zip.c: */ | 223 | /* from zip.c: */ |
225 | static int zip (int in, int out); | 224 | static int zip (int in, int out); |
226 | static int file_read (char *buf, unsigned size); | 225 | static int file_read (char *buf, unsigned size); |
@@ -248,6 +247,9 @@ static int (*read_buf) (char *buf, unsigned size); | |||
248 | /* from util.c: */ | 247 | /* from util.c: */ |
249 | static void flush_outbuf (void); | 248 | static void flush_outbuf (void); |
250 | 249 | ||
250 | static void put_short_when_full (ush); | ||
251 | |||
252 | |||
251 | /* lzw.h -- define the lzw functions. | 253 | /* lzw.h -- define the lzw functions. |
252 | * Copyright (C) 1992-1993 Jean-loup Gailly. | 254 | * Copyright (C) 1992-1993 Jean-loup Gailly. |
253 | * This is free software; you can redistribute it and/or modify it under the | 255 | * This is free software; you can redistribute it and/or modify it under the |
@@ -388,18 +390,11 @@ static ulg updcrc(uch *s, unsigned n) | |||
388 | static unsigned long crc_32_tab[256]; | 390 | static unsigned long crc_32_tab[256]; |
389 | if (crc_table_empty) { | 391 | if (crc_table_empty) { |
390 | unsigned long csr; /* crc shift register */ | 392 | unsigned long csr; /* crc shift register */ |
391 | unsigned long e=0; /* polynomial exclusive-or pattern */ | 393 | const unsigned long e = 0xedb88320L; /* polynomial exclusive-or pattern */ |
392 | int i; /* counter for all possible eight bit values */ | 394 | int i; /* counter for all possible eight bit values */ |
393 | int k; /* byte being shifted into crc apparatus */ | 395 | int k; /* byte being shifted into crc apparatus */ |
394 | 396 | ||
395 | /* terms of polynomial defining this crc (except x^32): */ | 397 | /* Compute table of CRC's. */ |
396 | static const int p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; | ||
397 | |||
398 | /* Make exclusive-or pattern from polynomial (0xedb88320) */ | ||
399 | for (i = 0; i < sizeof(p)/sizeof(int); i++) | ||
400 | e |= 1L << (31 - p[i]); | ||
401 | |||
402 | /* Compute and print table of CRC's, five per line */ | ||
403 | crc_32_tab[0] = 0x00000000L; | 398 | crc_32_tab[0] = 0x00000000L; |
404 | for (i = 1; i < 256; i++) { | 399 | for (i = 1; i < 256; i++) { |
405 | csr = i; | 400 | csr = i; |
@@ -1206,7 +1201,6 @@ typedef struct dirent dir_type; | |||
1206 | 1201 | ||
1207 | typedef RETSIGTYPE(*sig_type) (int); | 1202 | typedef RETSIGTYPE(*sig_type) (int); |
1208 | 1203 | ||
1209 | |||
1210 | /* ======================================================================== */ | 1204 | /* ======================================================================== */ |
1211 | // int main (argc, argv) | 1205 | // int main (argc, argv) |
1212 | // int argc; | 1206 | // int argc; |
@@ -1291,11 +1285,9 @@ int gzip_main(int argc, char **argv) | |||
1291 | 1285 | ||
1292 | /* Open input file */ | 1286 | /* Open input file */ |
1293 | inFileNum = open(ifname, O_RDONLY); | 1287 | inFileNum = open(ifname, O_RDONLY); |
1294 | if (inFileNum < 0) | 1288 | if (inFileNum < 0 || stat(ifname, &statBuf) < 0) |
1295 | perror_msg_and_die("%s", ifname); | 1289 | perror_msg_and_die("%s", ifname); |
1296 | /* Get the time stamp on the input file. */ | 1290 | /* Get the time stamp on the input file. */ |
1297 | if (stat(ifname, &statBuf) < 0) | ||
1298 | perror_msg_and_die("%s", ifname); | ||
1299 | time_stamp = statBuf.st_ctime; | 1291 | time_stamp = statBuf.st_ctime; |
1300 | ifile_size = statBuf.st_size; | 1292 | ifile_size = statBuf.st_size; |
1301 | } | 1293 | } |
@@ -1433,16 +1425,20 @@ int gzip_main(int argc, char **argv) | |||
1433 | #define BL_CODES 19 | 1425 | #define BL_CODES 19 |
1434 | /* number of codes used to transfer the bit lengths */ | 1426 | /* number of codes used to transfer the bit lengths */ |
1435 | 1427 | ||
1428 | typedef uch extra_bits_t; | ||
1436 | 1429 | ||
1437 | static const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */ | 1430 | /* extra bits for each length code */ |
1431 | static const extra_bits_t extra_lbits[LENGTH_CODES] | ||
1438 | = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, | 1432 | = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, |
1439 | 4, 4, 5, 5, 5, 5, 0 }; | 1433 | 4, 4, 5, 5, 5, 5, 0 }; |
1440 | 1434 | ||
1441 | static const int extra_dbits[D_CODES] /* extra bits for each distance code */ | 1435 | /* extra bits for each distance code */ |
1436 | static const extra_bits_t extra_dbits[D_CODES] | ||
1442 | = { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, | 1437 | = { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, |
1443 | 10, 10, 11, 11, 12, 12, 13, 13 }; | 1438 | 10, 10, 11, 11, 12, 12, 13, 13 }; |
1444 | 1439 | ||
1445 | static const int extra_blbits[BL_CODES] /* extra bits for each bit length code */ | 1440 | /* extra bits for each bit length code */ |
1441 | static const extra_bits_t extra_blbits[BL_CODES] | ||
1446 | = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7 }; | 1442 | = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7 }; |
1447 | 1443 | ||
1448 | #define STORED_BLOCK 0 | 1444 | #define STORED_BLOCK 0 |
@@ -1537,7 +1533,7 @@ static ct_data bl_tree[2 * BL_CODES + 1]; | |||
1537 | typedef struct tree_desc { | 1533 | typedef struct tree_desc { |
1538 | ct_data *dyn_tree; /* the dynamic tree */ | 1534 | ct_data *dyn_tree; /* the dynamic tree */ |
1539 | ct_data *static_tree; /* corresponding static tree or NULL */ | 1535 | ct_data *static_tree; /* corresponding static tree or NULL */ |
1540 | const int *extra_bits; /* extra bits for each code or NULL */ | 1536 | const extra_bits_t *extra_bits; /* extra bits for each code or NULL */ |
1541 | int extra_base; /* base index for extra_bits */ | 1537 | int extra_base; /* base index for extra_bits */ |
1542 | int elems; /* max number of elements in the tree */ | 1538 | int elems; /* max number of elements in the tree */ |
1543 | int max_length; /* max bit length for the codes */ | 1539 | int max_length; /* max bit length for the codes */ |
@@ -1834,7 +1830,7 @@ static void pqdownheap(ct_data *tree, int k) | |||
1834 | static void gen_bitlen(tree_desc *desc) | 1830 | static void gen_bitlen(tree_desc *desc) |
1835 | { | 1831 | { |
1836 | ct_data *tree = desc->dyn_tree; | 1832 | ct_data *tree = desc->dyn_tree; |
1837 | const int *extra = desc->extra_bits; | 1833 | const extra_bits_t *extra = desc->extra_bits; |
1838 | int base = desc->extra_base; | 1834 | int base = desc->extra_base; |
1839 | int max_code = desc->max_code; | 1835 | int max_code = desc->max_code; |
1840 | int max_length = desc->max_length; | 1836 | int max_length = desc->max_length; |
@@ -2466,6 +2462,28 @@ static void set_file_type() | |||
2466 | static ulg crc; /* crc on uncompressed file data */ | 2462 | static ulg crc; /* crc on uncompressed file data */ |
2467 | static long header_bytes; /* number of bytes in gzip header */ | 2463 | static long header_bytes; /* number of bytes in gzip header */ |
2468 | 2464 | ||
2465 | static void put_short_when_full(ush w) | ||
2466 | { | ||
2467 | put_byte((uch)((w) & 0xff)); | ||
2468 | put_byte((uch)((ush)(w) >> 8)); | ||
2469 | } | ||
2470 | |||
2471 | static void put_short_function(ush n) | ||
2472 | { | ||
2473 | put_short(n); | ||
2474 | } | ||
2475 | |||
2476 | static void put_long(ulg n) | ||
2477 | { | ||
2478 | put_short_function((n) & 0xffff); | ||
2479 | put_short_function(((ulg)(n)) >> 16); | ||
2480 | } | ||
2481 | |||
2482 | /* put_header_byte is used for the compressed output | ||
2483 | * - for the initial 4 bytes that can't overflow the buffer. | ||
2484 | */ | ||
2485 | #define put_header_byte(c) {outbuf[outcnt++]=(uch)(c);} | ||
2486 | |||
2469 | /* =========================================================================== | 2487 | /* =========================================================================== |
2470 | * Deflate in to out. | 2488 | * Deflate in to out. |
2471 | * IN assertions: the input and output buffers are cleared. | 2489 | * IN assertions: the input and output buffers are cleared. |
@@ -2485,11 +2503,11 @@ static int zip(int in, int out) | |||
2485 | 2503 | ||
2486 | 2504 | ||
2487 | method = DEFLATED; | 2505 | method = DEFLATED; |
2488 | put_byte(GZIP_MAGIC[0]); /* magic header */ | 2506 | put_header_byte(GZIP_MAGIC[0]); /* magic header */ |
2489 | put_byte(GZIP_MAGIC[1]); | 2507 | put_header_byte(GZIP_MAGIC[1]); |
2490 | put_byte(DEFLATED); /* compression method */ | 2508 | put_header_byte(DEFLATED); /* compression method */ |
2491 | 2509 | ||
2492 | put_byte(my_flags); /* general flags */ | 2510 | put_header_byte(my_flags); /* general flags */ |
2493 | put_long(time_stamp); | 2511 | put_long(time_stamp); |
2494 | 2512 | ||
2495 | /* Write deflated file to zip file */ | 2513 | /* Write deflated file to zip file */ |