unxz.c (1a36faad54665288ed4eb839d2a4699ae2ead45e) unxz.c (90f528e8d7868a5d31dc35b24943c673bf67821d)
1/* $NetBSD: unxz.c,v 1.6 2016/01/29 15:19:01 christos Exp $ */
1/* $NetBSD: unxz.c,v 1.7 2017/08/04 07:27:08 mrg Exp $ */
2
3/*-
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
9 *

--- 41 unchanged lines hidden (view full) ---

51 if (bytes_in == NULL)
52 bytes_in = &bp;
53
54 strm.next_in = ibuf;
55 memcpy(ibuf, pre, prelen);
56 strm.avail_in = read(i, ibuf + prelen, sizeof(ibuf) - prelen);
57 if (strm.avail_in == (size_t)-1)
58 maybe_err("read failed");
2
3/*-
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
9 *

--- 41 unchanged lines hidden (view full) ---

51 if (bytes_in == NULL)
52 bytes_in = &bp;
53
54 strm.next_in = ibuf;
55 memcpy(ibuf, pre, prelen);
56 strm.avail_in = read(i, ibuf + prelen, sizeof(ibuf) - prelen);
57 if (strm.avail_in == (size_t)-1)
58 maybe_err("read failed");
59 infile_newdata(strm.avail_in);
59 strm.avail_in += prelen;
60 *bytes_in = strm.avail_in;
61
62 if ((ret = lzma_stream_decoder(&strm, UINT64_MAX, flags)) != LZMA_OK)
63 maybe_errx("Can't initialize decoder (%d)", ret);
64
65 strm.next_out = NULL;
66 strm.avail_out = 0;
67 if ((ret = lzma_code(&strm, LZMA_RUN)) != LZMA_OK)
68 maybe_errx("Can't read headers (%d)", ret);
69
70 bytes_out = 0;
71 strm.next_out = obuf;
72 strm.avail_out = sizeof(obuf);
73
74 for (;;) {
60 strm.avail_in += prelen;
61 *bytes_in = strm.avail_in;
62
63 if ((ret = lzma_stream_decoder(&strm, UINT64_MAX, flags)) != LZMA_OK)
64 maybe_errx("Can't initialize decoder (%d)", ret);
65
66 strm.next_out = NULL;
67 strm.avail_out = 0;
68 if ((ret = lzma_code(&strm, LZMA_RUN)) != LZMA_OK)
69 maybe_errx("Can't read headers (%d)", ret);
70
71 bytes_out = 0;
72 strm.next_out = obuf;
73 strm.avail_out = sizeof(obuf);
74
75 for (;;) {
76 check_siginfo();
75 if (strm.avail_in == 0) {
76 strm.next_in = ibuf;
77 strm.avail_in = read(i, ibuf, sizeof(ibuf));
78 switch (strm.avail_in) {
79 case (size_t)-1:
80 maybe_err("read failed");
81 /*NOTREACHED*/
82 case 0:
83 action = LZMA_FINISH;
84 break;
85 default:
77 if (strm.avail_in == 0) {
78 strm.next_in = ibuf;
79 strm.avail_in = read(i, ibuf, sizeof(ibuf));
80 switch (strm.avail_in) {
81 case (size_t)-1:
82 maybe_err("read failed");
83 /*NOTREACHED*/
84 case 0:
85 action = LZMA_FINISH;
86 break;
87 default:
88 infile_newdata(strm.avail_in);
86 *bytes_in += strm.avail_in;
87 break;
88 }
89 }
90
91 ret = lzma_code(&strm, action);
92
93 // Write and check write error before checking decoder error.

--- 60 unchanged lines hidden ---
89 *bytes_in += strm.avail_in;
90 break;
91 }
92 }
93
94 ret = lzma_code(&strm, action);
95
96 // Write and check write error before checking decoder error.

--- 60 unchanged lines hidden ---