comparison zlib/examples/gzjoin.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents ae3a4bfb450b
children
comparison
equal deleted inserted replaced
68:561a7518be6b 111:04ced10e8804
1 /* gzjoin -- command to join gzip files into one gzip file 1 /* gzjoin -- command to join gzip files into one gzip file
2 2
3 Copyright (C) 2004 Mark Adler, all rights reserved 3 Copyright (C) 2004, 2005, 2012 Mark Adler, all rights reserved
4 version 1.0, 11 Dec 2004 4 version 1.2, 14 Aug 2012
5 5
6 This software is provided 'as-is', without any express or implied 6 This software is provided 'as-is', without any express or implied
7 warranty. In no event will the author be held liable for any damages 7 warranty. In no event will the author be held liable for any damages
8 arising from the use of this software. 8 arising from the use of this software.
9 9
25 /* 25 /*
26 * Change history: 26 * Change history:
27 * 27 *
28 * 1.0 11 Dec 2004 - First version 28 * 1.0 11 Dec 2004 - First version
29 * 1.1 12 Jun 2005 - Changed ssize_t to long for portability 29 * 1.1 12 Jun 2005 - Changed ssize_t to long for portability
30 * 1.2 14 Aug 2012 - Clean up for z_const usage
30 */ 31 */
31 32
32 /* 33 /*
33 gzjoin takes one or more gzip files on the command line and writes out a 34 gzjoin takes one or more gzip files on the command line and writes out a
34 single gzip file that will uncompress to the concatenation of the 35 single gzip file that will uncompress to the concatenation of the
306 bail("out of memory", ""); 307 bail("out of memory", "");
307 308
308 /* inflate and copy compressed data, clear last-block bit if requested */ 309 /* inflate and copy compressed data, clear last-block bit if requested */
309 len = 0; 310 len = 0;
310 zpull(&strm, in); 311 zpull(&strm, in);
311 start = strm.next_in; 312 start = in->next;
312 last = start[0] & 1; 313 last = start[0] & 1;
313 if (last && clr) 314 if (last && clr)
314 start[0] &= ~1; 315 start[0] &= ~1;
315 strm.avail_out = 0; 316 strm.avail_out = 0;
316 for (;;) { 317 for (;;) {
349 if (pos != 0) { 350 if (pos != 0) {
350 /* next last-block bit is in last used byte */ 351 /* next last-block bit is in last used byte */
351 pos = 0x100 >> pos; 352 pos = 0x100 >> pos;
352 last = strm.next_in[-1] & pos; 353 last = strm.next_in[-1] & pos;
353 if (last && clr) 354 if (last && clr)
354 strm.next_in[-1] &= ~pos; 355 in->buf[strm.next_in - in->buf - 1] &= ~pos;
355 } 356 }
356 else { 357 else {
357 /* next last-block bit is in next unused byte */ 358 /* next last-block bit is in next unused byte */
358 if (strm.avail_in == 0) { 359 if (strm.avail_in == 0) {
359 /* don't have that byte yet -- get it */ 360 /* don't have that byte yet -- get it */
362 in->left = 0; 363 in->left = 0;
363 zpull(&strm, in); 364 zpull(&strm, in);
364 } 365 }
365 last = strm.next_in[0] & 1; 366 last = strm.next_in[0] & 1;
366 if (last && clr) 367 if (last && clr)
367 strm.next_in[0] &= ~1; 368 in->buf[strm.next_in - in->buf] &= ~1;
368 } 369 }
369 } 370 }
370 } 371 }
371 372
372 /* update buffer with unused input */ 373 /* update buffer with unused input */
373 in->left = strm.avail_in; 374 in->left = strm.avail_in;
374 in->next = strm.next_in; 375 in->next = in->buf + (strm.next_in - in->buf);
375 376
376 /* copy used input, write empty blocks to get to byte boundary */ 377 /* copy used input, write empty blocks to get to byte boundary */
377 pos = strm.data_type & 7; 378 pos = strm.data_type & 7;
378 fwrite(start, 1, in->next - start - 1, out); 379 fwrite(start, 1, in->next - start - 1, out);
379 last = in->next[-1]; 380 last = in->next[-1];