Blame


1 a76a38d9 2018-03-11 stsp /*
2 a76a38d9 2018-03-11 stsp * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
3 a76a38d9 2018-03-11 stsp *
4 a76a38d9 2018-03-11 stsp * Permission to use, copy, modify, and distribute this software for any
5 a76a38d9 2018-03-11 stsp * purpose with or without fee is hereby granted, provided that the above
6 a76a38d9 2018-03-11 stsp * copyright notice and this permission notice appear in all copies.
7 a76a38d9 2018-03-11 stsp *
8 a76a38d9 2018-03-11 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 a76a38d9 2018-03-11 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 a76a38d9 2018-03-11 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 a76a38d9 2018-03-11 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 a76a38d9 2018-03-11 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 a76a38d9 2018-03-11 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 a76a38d9 2018-03-11 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 a76a38d9 2018-03-11 stsp */
16 a76a38d9 2018-03-11 stsp
17 a76a38d9 2018-03-11 stsp #include <sys/queue.h>
18 a76a38d9 2018-03-11 stsp
19 a76a38d9 2018-03-11 stsp #include <stdio.h>
20 a76a38d9 2018-03-11 stsp #include <stdlib.h>
21 a76a38d9 2018-03-11 stsp #include <string.h>
22 a76a38d9 2018-03-11 stsp #include <sha1.h>
23 a76a38d9 2018-03-11 stsp #include <zlib.h>
24 788c352e 2018-06-16 stsp #include <time.h>
25 a76a38d9 2018-03-11 stsp
26 a76a38d9 2018-03-11 stsp #include "got_error.h"
27 a76a38d9 2018-03-11 stsp #include "got_object.h"
28 a76a38d9 2018-03-11 stsp
29 718b3ab0 2018-03-17 stsp #include "got_lib_path.h"
30 718b3ab0 2018-03-17 stsp #include "got_lib_zbuf.h"
31 a76a38d9 2018-03-11 stsp
32 a76a38d9 2018-03-11 stsp const struct got_error *
33 19d747f7 2018-03-16 stsp got_inflate_init(struct got_zstream_buf *zb, uint8_t *outbuf, size_t bufsize)
34 a76a38d9 2018-03-11 stsp {
35 a76a38d9 2018-03-11 stsp const struct got_error *err = NULL;
36 a76a38d9 2018-03-11 stsp
37 a76a38d9 2018-03-11 stsp memset(zb, 0, sizeof(*zb));
38 a76a38d9 2018-03-11 stsp
39 a76a38d9 2018-03-11 stsp zb->z.zalloc = Z_NULL;
40 a76a38d9 2018-03-11 stsp zb->z.zfree = Z_NULL;
41 a76a38d9 2018-03-11 stsp if (inflateInit(&zb->z) != Z_OK) {
42 a76a38d9 2018-03-11 stsp err = got_error(GOT_ERR_IO);
43 a76a38d9 2018-03-11 stsp goto done;
44 a76a38d9 2018-03-11 stsp }
45 a76a38d9 2018-03-11 stsp
46 a76a38d9 2018-03-11 stsp zb->inlen = zb->outlen = bufsize;
47 a76a38d9 2018-03-11 stsp
48 a76a38d9 2018-03-11 stsp zb->inbuf = calloc(1, zb->inlen);
49 a76a38d9 2018-03-11 stsp if (zb->inbuf == NULL) {
50 0a585a0d 2018-03-17 stsp err = got_error_from_errno();
51 a76a38d9 2018-03-11 stsp goto done;
52 a76a38d9 2018-03-11 stsp }
53 a76a38d9 2018-03-11 stsp
54 19d747f7 2018-03-16 stsp if (outbuf == NULL) {
55 19d747f7 2018-03-16 stsp zb->outbuf = calloc(1, zb->outlen);
56 19d747f7 2018-03-16 stsp if (zb->outbuf == NULL) {
57 0a585a0d 2018-03-17 stsp err = got_error_from_errno();
58 19d747f7 2018-03-16 stsp goto done;
59 19d747f7 2018-03-16 stsp }
60 19d747f7 2018-03-16 stsp zb->flags |= GOT_ZSTREAM_F_OWN_OUTBUF;
61 19d747f7 2018-03-16 stsp } else
62 19d747f7 2018-03-16 stsp zb->outbuf = outbuf;
63 a76a38d9 2018-03-11 stsp
64 a76a38d9 2018-03-11 stsp done:
65 a76a38d9 2018-03-11 stsp if (err)
66 a76a38d9 2018-03-11 stsp got_inflate_end(zb);
67 a76a38d9 2018-03-11 stsp return err;
68 a76a38d9 2018-03-11 stsp }
69 a76a38d9 2018-03-11 stsp
70 a76a38d9 2018-03-11 stsp const struct got_error *
71 a76a38d9 2018-03-11 stsp got_inflate_read(struct got_zstream_buf *zb, FILE *f, size_t *outlenp)
72 a76a38d9 2018-03-11 stsp {
73 a76a38d9 2018-03-11 stsp size_t last_total_out = zb->z.total_out;
74 a76a38d9 2018-03-11 stsp z_stream *z = &zb->z;
75 92088384 2018-04-01 stsp int ret = Z_ERRNO;
76 a76a38d9 2018-03-11 stsp
77 a76a38d9 2018-03-11 stsp z->next_out = zb->outbuf;
78 a76a38d9 2018-03-11 stsp z->avail_out = zb->outlen;
79 a76a38d9 2018-03-11 stsp
80 a76a38d9 2018-03-11 stsp *outlenp = 0;
81 a76a38d9 2018-03-11 stsp do {
82 a76a38d9 2018-03-11 stsp if (z->avail_in == 0) {
83 a76a38d9 2018-03-11 stsp size_t n = fread(zb->inbuf, 1, zb->inlen, f);
84 a76a38d9 2018-03-11 stsp if (n == 0) {
85 a76a38d9 2018-03-11 stsp if (ferror(f))
86 a76a38d9 2018-03-11 stsp return got_ferror(f, GOT_ERR_IO);
87 92088384 2018-04-01 stsp /* EOF */
88 92088384 2018-04-01 stsp ret = Z_STREAM_END;
89 92088384 2018-04-01 stsp break;
90 a76a38d9 2018-03-11 stsp }
91 a76a38d9 2018-03-11 stsp z->next_in = zb->inbuf;
92 a76a38d9 2018-03-11 stsp z->avail_in = n;
93 a76a38d9 2018-03-11 stsp }
94 a76a38d9 2018-03-11 stsp ret = inflate(z, Z_SYNC_FLUSH);
95 a76a38d9 2018-03-11 stsp } while (ret == Z_OK && z->avail_out > 0);
96 a76a38d9 2018-03-11 stsp
97 a76a38d9 2018-03-11 stsp if (ret == Z_OK) {
98 a76a38d9 2018-03-11 stsp zb->flags |= GOT_ZSTREAM_F_HAVE_MORE;
99 a76a38d9 2018-03-11 stsp } else {
100 a76a38d9 2018-03-11 stsp if (ret != Z_STREAM_END)
101 a76a38d9 2018-03-11 stsp return got_error(GOT_ERR_DECOMPRESSION);
102 a76a38d9 2018-03-11 stsp zb->flags &= ~GOT_ZSTREAM_F_HAVE_MORE;
103 a76a38d9 2018-03-11 stsp }
104 a76a38d9 2018-03-11 stsp
105 a76a38d9 2018-03-11 stsp *outlenp = z->total_out - last_total_out;
106 a76a38d9 2018-03-11 stsp return NULL;
107 a76a38d9 2018-03-11 stsp }
108 a76a38d9 2018-03-11 stsp
109 962916a2 2018-04-24 stsp const struct got_error *
110 962916a2 2018-04-24 stsp got_inflate_read_fd(struct got_zstream_buf *zb, int fd, size_t *outlenp)
111 962916a2 2018-04-24 stsp {
112 962916a2 2018-04-24 stsp size_t last_total_out = zb->z.total_out;
113 962916a2 2018-04-24 stsp z_stream *z = &zb->z;
114 962916a2 2018-04-24 stsp int ret = Z_ERRNO;
115 962916a2 2018-04-24 stsp
116 962916a2 2018-04-24 stsp z->next_out = zb->outbuf;
117 962916a2 2018-04-24 stsp z->avail_out = zb->outlen;
118 962916a2 2018-04-24 stsp
119 962916a2 2018-04-24 stsp *outlenp = 0;
120 962916a2 2018-04-24 stsp do {
121 962916a2 2018-04-24 stsp if (z->avail_in == 0) {
122 962916a2 2018-04-24 stsp ssize_t n = read(fd, zb->inbuf, zb->inlen);
123 962916a2 2018-04-24 stsp if (n < 0)
124 962916a2 2018-04-24 stsp return got_error_from_errno();
125 962916a2 2018-04-24 stsp else if (n == 0) {
126 962916a2 2018-04-24 stsp /* EOF */
127 962916a2 2018-04-24 stsp ret = Z_STREAM_END;
128 962916a2 2018-04-24 stsp break;
129 962916a2 2018-04-24 stsp }
130 962916a2 2018-04-24 stsp z->next_in = zb->inbuf;
131 962916a2 2018-04-24 stsp z->avail_in = n;
132 962916a2 2018-04-24 stsp }
133 962916a2 2018-04-24 stsp ret = inflate(z, Z_SYNC_FLUSH);
134 962916a2 2018-04-24 stsp } while (ret == Z_OK && z->avail_out > 0);
135 962916a2 2018-04-24 stsp
136 962916a2 2018-04-24 stsp if (ret == Z_OK) {
137 962916a2 2018-04-24 stsp zb->flags |= GOT_ZSTREAM_F_HAVE_MORE;
138 962916a2 2018-04-24 stsp } else {
139 962916a2 2018-04-24 stsp if (ret != Z_STREAM_END)
140 962916a2 2018-04-24 stsp return got_error(GOT_ERR_DECOMPRESSION);
141 962916a2 2018-04-24 stsp zb->flags &= ~GOT_ZSTREAM_F_HAVE_MORE;
142 962916a2 2018-04-24 stsp }
143 962916a2 2018-04-24 stsp
144 962916a2 2018-04-24 stsp *outlenp = z->total_out - last_total_out;
145 962916a2 2018-04-24 stsp return NULL;
146 962916a2 2018-04-24 stsp }
147 962916a2 2018-04-24 stsp
148 a76a38d9 2018-03-11 stsp void
149 a76a38d9 2018-03-11 stsp got_inflate_end(struct got_zstream_buf *zb)
150 a76a38d9 2018-03-11 stsp {
151 a76a38d9 2018-03-11 stsp free(zb->inbuf);
152 19d747f7 2018-03-16 stsp if (zb->flags & GOT_ZSTREAM_F_OWN_OUTBUF)
153 19d747f7 2018-03-16 stsp free(zb->outbuf);
154 a76a38d9 2018-03-11 stsp inflateEnd(&zb->z);
155 a76a38d9 2018-03-11 stsp }
156 a76a38d9 2018-03-11 stsp
157 a76a38d9 2018-03-11 stsp const struct got_error *
158 a76a38d9 2018-03-11 stsp got_inflate_to_mem(uint8_t **outbuf, size_t *outlen, FILE *f)
159 a76a38d9 2018-03-11 stsp {
160 a76a38d9 2018-03-11 stsp const struct got_error *err;
161 a76a38d9 2018-03-11 stsp size_t avail;
162 a76a38d9 2018-03-11 stsp struct got_zstream_buf zb;
163 a76a38d9 2018-03-11 stsp void *newbuf;
164 a76a38d9 2018-03-11 stsp
165 19d747f7 2018-03-16 stsp *outbuf = calloc(1, GOT_ZSTREAM_BUFSIZE);
166 19d747f7 2018-03-16 stsp if (*outbuf == NULL)
167 0a585a0d 2018-03-17 stsp return got_error_from_errno();
168 19d747f7 2018-03-16 stsp err = got_inflate_init(&zb, *outbuf, GOT_ZSTREAM_BUFSIZE);
169 a76a38d9 2018-03-11 stsp if (err)
170 a76a38d9 2018-03-11 stsp return err;
171 a76a38d9 2018-03-11 stsp
172 a76a38d9 2018-03-11 stsp *outlen = 0;
173 a76a38d9 2018-03-11 stsp
174 a76a38d9 2018-03-11 stsp do {
175 a76a38d9 2018-03-11 stsp err = got_inflate_read(&zb, f, &avail);
176 a76a38d9 2018-03-11 stsp if (err)
177 a76a38d9 2018-03-11 stsp return err;
178 19d747f7 2018-03-16 stsp *outlen += avail;
179 19d747f7 2018-03-16 stsp if (zb.flags & GOT_ZSTREAM_F_HAVE_MORE) {
180 19d747f7 2018-03-16 stsp newbuf = reallocarray(*outbuf, 1,
181 19d747f7 2018-03-16 stsp *outlen + GOT_ZSTREAM_BUFSIZE);
182 a76a38d9 2018-03-11 stsp if (newbuf == NULL) {
183 0a585a0d 2018-03-17 stsp err = got_error_from_errno();
184 a76a38d9 2018-03-11 stsp free(*outbuf);
185 a76a38d9 2018-03-11 stsp *outbuf = NULL;
186 a76a38d9 2018-03-11 stsp *outlen = 0;
187 a76a38d9 2018-03-11 stsp goto done;
188 a76a38d9 2018-03-11 stsp }
189 a76a38d9 2018-03-11 stsp *outbuf = newbuf;
190 19d747f7 2018-03-16 stsp zb.outbuf = newbuf + *outlen;
191 19d747f7 2018-03-16 stsp zb.outlen = GOT_ZSTREAM_BUFSIZE;
192 a76a38d9 2018-03-11 stsp }
193 a76a38d9 2018-03-11 stsp } while (zb.flags & GOT_ZSTREAM_F_HAVE_MORE);
194 a76a38d9 2018-03-11 stsp
195 a76a38d9 2018-03-11 stsp done:
196 a76a38d9 2018-03-11 stsp got_inflate_end(&zb);
197 a76a38d9 2018-03-11 stsp return err;
198 a76a38d9 2018-03-11 stsp }
199 a76a38d9 2018-03-11 stsp
200 a76a38d9 2018-03-11 stsp const struct got_error *
201 8b2180d4 2018-04-26 stsp got_inflate_to_mem_fd(uint8_t **outbuf, size_t *outlen, int infd)
202 8b2180d4 2018-04-26 stsp {
203 8b2180d4 2018-04-26 stsp const struct got_error *err;
204 8b2180d4 2018-04-26 stsp size_t avail;
205 8b2180d4 2018-04-26 stsp struct got_zstream_buf zb;
206 8b2180d4 2018-04-26 stsp void *newbuf;
207 8b2180d4 2018-04-26 stsp
208 8b2180d4 2018-04-26 stsp *outbuf = calloc(1, GOT_ZSTREAM_BUFSIZE);
209 8b2180d4 2018-04-26 stsp if (*outbuf == NULL)
210 8b2180d4 2018-04-26 stsp return got_error_from_errno();
211 8b2180d4 2018-04-26 stsp err = got_inflate_init(&zb, *outbuf, GOT_ZSTREAM_BUFSIZE);
212 8b2180d4 2018-04-26 stsp if (err)
213 8b2180d4 2018-04-26 stsp return err;
214 8b2180d4 2018-04-26 stsp
215 8b2180d4 2018-04-26 stsp *outlen = 0;
216 8b2180d4 2018-04-26 stsp
217 8b2180d4 2018-04-26 stsp do {
218 8b2180d4 2018-04-26 stsp err = got_inflate_read_fd(&zb, infd, &avail);
219 8b2180d4 2018-04-26 stsp if (err)
220 8b2180d4 2018-04-26 stsp return err;
221 8b2180d4 2018-04-26 stsp *outlen += avail;
222 8b2180d4 2018-04-26 stsp if (zb.flags & GOT_ZSTREAM_F_HAVE_MORE) {
223 8b2180d4 2018-04-26 stsp newbuf = reallocarray(*outbuf, 1,
224 8b2180d4 2018-04-26 stsp *outlen + GOT_ZSTREAM_BUFSIZE);
225 8b2180d4 2018-04-26 stsp if (newbuf == NULL) {
226 8b2180d4 2018-04-26 stsp err = got_error_from_errno();
227 8b2180d4 2018-04-26 stsp free(*outbuf);
228 8b2180d4 2018-04-26 stsp *outbuf = NULL;
229 8b2180d4 2018-04-26 stsp *outlen = 0;
230 8b2180d4 2018-04-26 stsp goto done;
231 8b2180d4 2018-04-26 stsp }
232 8b2180d4 2018-04-26 stsp *outbuf = newbuf;
233 8b2180d4 2018-04-26 stsp zb.outbuf = newbuf + *outlen;
234 8b2180d4 2018-04-26 stsp zb.outlen = GOT_ZSTREAM_BUFSIZE;
235 8b2180d4 2018-04-26 stsp }
236 8b2180d4 2018-04-26 stsp } while (zb.flags & GOT_ZSTREAM_F_HAVE_MORE);
237 8b2180d4 2018-04-26 stsp
238 8b2180d4 2018-04-26 stsp done:
239 8b2180d4 2018-04-26 stsp got_inflate_end(&zb);
240 8b2180d4 2018-04-26 stsp return err;
241 8b2180d4 2018-04-26 stsp }
242 8b2180d4 2018-04-26 stsp
243 8b2180d4 2018-04-26 stsp const struct got_error *
244 8b2180d4 2018-04-26 stsp got_inflate_to_fd(size_t *outlen, FILE *infile, int outfd)
245 962916a2 2018-04-24 stsp {
246 962916a2 2018-04-24 stsp const struct got_error *err = NULL;
247 962916a2 2018-04-24 stsp size_t avail;
248 962916a2 2018-04-24 stsp struct got_zstream_buf zb;
249 962916a2 2018-04-24 stsp
250 962916a2 2018-04-24 stsp err = got_inflate_init(&zb, NULL, GOT_ZSTREAM_BUFSIZE);
251 962916a2 2018-04-24 stsp if (err)
252 962916a2 2018-04-24 stsp goto done;
253 962916a2 2018-04-24 stsp
254 962916a2 2018-04-24 stsp *outlen = 0;
255 962916a2 2018-04-24 stsp
256 962916a2 2018-04-24 stsp do {
257 8b2180d4 2018-04-26 stsp err = got_inflate_read(&zb, infile, &avail);
258 962916a2 2018-04-24 stsp if (err)
259 962916a2 2018-04-24 stsp return err;
260 962916a2 2018-04-24 stsp if (avail > 0) {
261 962916a2 2018-04-24 stsp ssize_t n;
262 962916a2 2018-04-24 stsp n = write(outfd, zb.outbuf, avail);
263 962916a2 2018-04-24 stsp if (n != avail) {
264 962916a2 2018-04-24 stsp err = got_error_from_errno();
265 962916a2 2018-04-24 stsp goto done;
266 962916a2 2018-04-24 stsp }
267 962916a2 2018-04-24 stsp *outlen += avail;
268 962916a2 2018-04-24 stsp }
269 962916a2 2018-04-24 stsp } while (zb.flags & GOT_ZSTREAM_F_HAVE_MORE);
270 962916a2 2018-04-24 stsp
271 962916a2 2018-04-24 stsp done:
272 962916a2 2018-04-24 stsp if (err == NULL) {
273 962916a2 2018-04-24 stsp if (lseek(outfd, SEEK_SET, 0) == -1)
274 962916a2 2018-04-24 stsp err = got_error_from_errno();
275 962916a2 2018-04-24 stsp }
276 962916a2 2018-04-24 stsp got_inflate_end(&zb);
277 962916a2 2018-04-24 stsp return err;
278 962916a2 2018-04-24 stsp }
279 962916a2 2018-04-24 stsp
280 962916a2 2018-04-24 stsp const struct got_error *
281 a76a38d9 2018-03-11 stsp got_inflate_to_file(size_t *outlen, FILE *infile, FILE *outfile)
282 a76a38d9 2018-03-11 stsp {
283 a76a38d9 2018-03-11 stsp const struct got_error *err;
284 a76a38d9 2018-03-11 stsp size_t avail;
285 a76a38d9 2018-03-11 stsp struct got_zstream_buf zb;
286 a76a38d9 2018-03-11 stsp
287 19d747f7 2018-03-16 stsp err = got_inflate_init(&zb, NULL, GOT_ZSTREAM_BUFSIZE);
288 a76a38d9 2018-03-11 stsp if (err)
289 a76a38d9 2018-03-11 stsp goto done;
290 a76a38d9 2018-03-11 stsp
291 a76a38d9 2018-03-11 stsp *outlen = 0;
292 a76a38d9 2018-03-11 stsp
293 a76a38d9 2018-03-11 stsp do {
294 a76a38d9 2018-03-11 stsp err = got_inflate_read(&zb, infile, &avail);
295 a76a38d9 2018-03-11 stsp if (err)
296 a76a38d9 2018-03-11 stsp return err;
297 a76a38d9 2018-03-11 stsp if (avail > 0) {
298 a76a38d9 2018-03-11 stsp size_t n;
299 a76a38d9 2018-03-11 stsp n = fwrite(zb.outbuf, avail, 1, outfile);
300 a76a38d9 2018-03-11 stsp if (n != 1) {
301 a76a38d9 2018-03-11 stsp err = got_ferror(outfile, GOT_ERR_IO);
302 a76a38d9 2018-03-11 stsp goto done;
303 a76a38d9 2018-03-11 stsp }
304 a76a38d9 2018-03-11 stsp *outlen += avail;
305 a76a38d9 2018-03-11 stsp }
306 a76a38d9 2018-03-11 stsp } while (zb.flags & GOT_ZSTREAM_F_HAVE_MORE);
307 a76a38d9 2018-03-11 stsp
308 a76a38d9 2018-03-11 stsp done:
309 a76a38d9 2018-03-11 stsp if (err == NULL)
310 a76a38d9 2018-03-11 stsp rewind(outfile);
311 a76a38d9 2018-03-11 stsp got_inflate_end(&zb);
312 a76a38d9 2018-03-11 stsp return err;
313 a76a38d9 2018-03-11 stsp }
314 8b2180d4 2018-04-26 stsp
315 8b2180d4 2018-04-26 stsp const struct got_error *
316 8b2180d4 2018-04-26 stsp got_inflate_to_file_fd(size_t *outlen, int infd, FILE *outfile)
317 8b2180d4 2018-04-26 stsp {
318 8b2180d4 2018-04-26 stsp const struct got_error *err;
319 8b2180d4 2018-04-26 stsp size_t avail;
320 8b2180d4 2018-04-26 stsp struct got_zstream_buf zb;
321 8b2180d4 2018-04-26 stsp
322 8b2180d4 2018-04-26 stsp err = got_inflate_init(&zb, NULL, GOT_ZSTREAM_BUFSIZE);
323 8b2180d4 2018-04-26 stsp if (err)
324 8b2180d4 2018-04-26 stsp goto done;
325 8b2180d4 2018-04-26 stsp
326 8b2180d4 2018-04-26 stsp *outlen = 0;
327 8b2180d4 2018-04-26 stsp
328 8b2180d4 2018-04-26 stsp do {
329 8b2180d4 2018-04-26 stsp err = got_inflate_read_fd(&zb, infd, &avail);
330 8b2180d4 2018-04-26 stsp if (err)
331 8b2180d4 2018-04-26 stsp return err;
332 8b2180d4 2018-04-26 stsp if (avail > 0) {
333 8b2180d4 2018-04-26 stsp size_t n;
334 8b2180d4 2018-04-26 stsp n = fwrite(zb.outbuf, avail, 1, outfile);
335 8b2180d4 2018-04-26 stsp if (n != 1) {
336 8b2180d4 2018-04-26 stsp err = got_ferror(outfile, GOT_ERR_IO);
337 8b2180d4 2018-04-26 stsp goto done;
338 8b2180d4 2018-04-26 stsp }
339 8b2180d4 2018-04-26 stsp *outlen += avail;
340 8b2180d4 2018-04-26 stsp }
341 8b2180d4 2018-04-26 stsp } while (zb.flags & GOT_ZSTREAM_F_HAVE_MORE);
342 8b2180d4 2018-04-26 stsp
343 8b2180d4 2018-04-26 stsp done:
344 8b2180d4 2018-04-26 stsp if (err == NULL)
345 8b2180d4 2018-04-26 stsp rewind(outfile);
346 8b2180d4 2018-04-26 stsp got_inflate_end(&zb);
347 8b2180d4 2018-04-26 stsp return err;
348 8b2180d4 2018-04-26 stsp }