aboutsummaryrefslogtreecommitdiff
path: root/archival/gzip.c
diff options
context:
space:
mode:
Diffstat (limited to 'archival/gzip.c')
-rw-r--r--archival/gzip.c61
1 files changed, 50 insertions, 11 deletions
diff --git a/archival/gzip.c b/archival/gzip.c
index a93d2175a..bc1f9c60b 100644
--- a/archival/gzip.c
+++ b/archival/gzip.c
@@ -417,19 +417,46 @@ static void flush_outbuf(void)
417#define put_8bit(c) \ 417#define put_8bit(c) \
418do { \ 418do { \
419 G1.outbuf[G1.outcnt++] = (c); \ 419 G1.outbuf[G1.outcnt++] = (c); \
420 if (G1.outcnt == OUTBUFSIZ) flush_outbuf(); \ 420 if (G1.outcnt == OUTBUFSIZ) \
421 flush_outbuf(); \
421} while (0) 422} while (0)
422 423
423/* Output a 16 bit value, lsb first */ 424/* Output a 16 bit value, lsb first */
424static void put_16bit(ush w) 425static void put_16bit(ush w)
425{ 426{
426 if (G1.outcnt < OUTBUFSIZ - 2) { 427 /* GCC 4.2.1 won't optimize out redundant loads of G1.outcnt
427 G1.outbuf[G1.outcnt++] = w; 428 * (probably because of fear of aliasing with G1.outbuf[]
428 G1.outbuf[G1.outcnt++] = w >> 8; 429 * stores), do it explicitly:
429 } else { 430 */
430 put_8bit(w); 431 unsigned outcnt = G1.outcnt;
431 put_8bit(w >> 8); 432 uch *dst = &G1.outbuf[outcnt];
433
434#if BB_UNALIGNED_MEMACCESS_OK && BB_LITTLE_ENDIAN
435 if (outcnt < OUTBUFSIZ-2) {
436 /* Common case */
437 ush *dst16 = (void*) dst;
438 *dst16 = w; /* unalinged LSB 16-bit store */
439 G1.outcnt = outcnt + 2;
440 return;
432 } 441 }
442 *dst = (uch)w;
443 w >>= 8;
444#else
445 *dst = (uch)w;
446 w >>= 8;
447 if (outcnt < OUTBUFSIZ-2) {
448 /* Common case */
449 dst[1] = w;
450 G1.outcnt = outcnt + 2;
451 return;
452 }
453#endif
454
455 /* Slowpath: we will need to do flush_outbuf() */
456 G1.outcnt = ++outcnt;
457 if (outcnt == OUTBUFSIZ)
458 flush_outbuf();
459 put_8bit(w);
433} 460}
434 461
435static void put_32bit(ulg n) 462static void put_32bit(ulg n)
@@ -2007,7 +2034,7 @@ static void ct_init(void)
2007 * IN assertions: the input and output buffers are cleared. 2034 * IN assertions: the input and output buffers are cleared.
2008 */ 2035 */
2009 2036
2010static void zip(ulg time_stamp) 2037static void zip(void)
2011{ 2038{
2012 ush deflate_flags = 0; /* pkzip -es, -en or -ex equivalent */ 2039 ush deflate_flags = 0; /* pkzip -es, -en or -ex equivalent */
2013 2040
@@ -2018,7 +2045,7 @@ static void zip(ulg time_stamp)
2018 /* compression method: 8 (DEFLATED) */ 2045 /* compression method: 8 (DEFLATED) */
2019 /* general flags: 0 */ 2046 /* general flags: 0 */
2020 put_32bit(0x00088b1f); 2047 put_32bit(0x00088b1f);
2021 put_32bit(time_stamp); 2048 put_32bit(0); /* Unix timestamp */
2022 2049
2023 /* Write deflated file to zip file */ 2050 /* Write deflated file to zip file */
2024 G1.crc = ~0; 2051 G1.crc = ~0;
@@ -2044,8 +2071,6 @@ static void zip(ulg time_stamp)
2044static 2071static
2045IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_state_t *xstate UNUSED_PARAM) 2072IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_state_t *xstate UNUSED_PARAM)
2046{ 2073{
2047 struct stat s;
2048
2049 /* Clear input and output buffers */ 2074 /* Clear input and output buffers */
2050 G1.outcnt = 0; 2075 G1.outcnt = 0;
2051#ifdef DEBUG 2076#ifdef DEBUG
@@ -2077,9 +2102,23 @@ IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_state_t *xstate UNUSED
2077 G2.bl_desc.max_length = MAX_BL_BITS; 2102 G2.bl_desc.max_length = MAX_BL_BITS;
2078 //G2.bl_desc.max_code = 0; 2103 //G2.bl_desc.max_code = 0;
2079 2104
2105#if 0
2106 /* Saving of timestamp is disabled. Why?
2107 * - it is not Y2038-safe.
2108 * - some people want deterministic results
2109 * (normally they'd use -n, but our -n is a nop).
2110 * - it's bloat.
2111 * Per RFC 1952, gzfile.time=0 is "no timestamp".
2112 * If users will demand this to be reinstated,
2113 * implement -n "don't save timestamp".
2114 */
2115 struct stat s;
2080 s.st_ctime = 0; 2116 s.st_ctime = 0;
2081 fstat(STDIN_FILENO, &s); 2117 fstat(STDIN_FILENO, &s);
2082 zip(s.st_ctime); 2118 zip(s.st_ctime);
2119#else
2120 zip();
2121#endif
2083 return 0; 2122 return 0;
2084} 2123}
2085 2124