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 a76a38d9 2018-03-11 stsp
25 a76a38d9 2018-03-11 stsp #include "got_error.h"
26 a76a38d9 2018-03-11 stsp #include "got_object.h"
27 a76a38d9 2018-03-11 stsp
28 718b3ab0 2018-03-17 stsp #include "got_lib_path.h"
29 718b3ab0 2018-03-17 stsp #include "got_lib_zbuf.h"
30 a76a38d9 2018-03-11 stsp
31 a76a38d9 2018-03-11 stsp const struct got_error *
32 19d747f7 2018-03-16 stsp got_inflate_init(struct got_zstream_buf *zb, uint8_t *outbuf, size_t bufsize)
33 a76a38d9 2018-03-11 stsp {
34 a76a38d9 2018-03-11 stsp const struct got_error *err = NULL;
35 a76a38d9 2018-03-11 stsp
36 a76a38d9 2018-03-11 stsp memset(zb, 0, sizeof(*zb));
37 a76a38d9 2018-03-11 stsp
38 a76a38d9 2018-03-11 stsp zb->z.zalloc = Z_NULL;
39 a76a38d9 2018-03-11 stsp zb->z.zfree = Z_NULL;
40 a76a38d9 2018-03-11 stsp if (inflateInit(&zb->z) != Z_OK) {
41 a76a38d9 2018-03-11 stsp err = got_error(GOT_ERR_IO);
42 a76a38d9 2018-03-11 stsp goto done;
43 a76a38d9 2018-03-11 stsp }
44 a76a38d9 2018-03-11 stsp
45 a76a38d9 2018-03-11 stsp zb->inlen = zb->outlen = bufsize;
46 a76a38d9 2018-03-11 stsp
47 a76a38d9 2018-03-11 stsp zb->inbuf = calloc(1, zb->inlen);
48 a76a38d9 2018-03-11 stsp if (zb->inbuf == NULL) {
49 0a585a0d 2018-03-17 stsp err = got_error_from_errno();
50 a76a38d9 2018-03-11 stsp goto done;
51 a76a38d9 2018-03-11 stsp }
52 a76a38d9 2018-03-11 stsp
53 19d747f7 2018-03-16 stsp if (outbuf == NULL) {
54 19d747f7 2018-03-16 stsp zb->outbuf = calloc(1, zb->outlen);
55 19d747f7 2018-03-16 stsp if (zb->outbuf == NULL) {
56 0a585a0d 2018-03-17 stsp err = got_error_from_errno();
57 19d747f7 2018-03-16 stsp goto done;
58 19d747f7 2018-03-16 stsp }
59 19d747f7 2018-03-16 stsp zb->flags |= GOT_ZSTREAM_F_OWN_OUTBUF;
60 19d747f7 2018-03-16 stsp } else
61 19d747f7 2018-03-16 stsp zb->outbuf = outbuf;
62 a76a38d9 2018-03-11 stsp
63 a76a38d9 2018-03-11 stsp done:
64 a76a38d9 2018-03-11 stsp if (err)
65 a76a38d9 2018-03-11 stsp got_inflate_end(zb);
66 a76a38d9 2018-03-11 stsp return err;
67 a76a38d9 2018-03-11 stsp }
68 a76a38d9 2018-03-11 stsp
69 a76a38d9 2018-03-11 stsp const struct got_error *
70 a76a38d9 2018-03-11 stsp got_inflate_read(struct got_zstream_buf *zb, FILE *f, size_t *outlenp)
71 a76a38d9 2018-03-11 stsp {
72 a76a38d9 2018-03-11 stsp size_t last_total_out = zb->z.total_out;
73 a76a38d9 2018-03-11 stsp z_stream *z = &zb->z;
74 92088384 2018-04-01 stsp int ret = Z_ERRNO;
75 a76a38d9 2018-03-11 stsp
76 a76a38d9 2018-03-11 stsp z->next_out = zb->outbuf;
77 a76a38d9 2018-03-11 stsp z->avail_out = zb->outlen;
78 a76a38d9 2018-03-11 stsp
79 a76a38d9 2018-03-11 stsp *outlenp = 0;
80 a76a38d9 2018-03-11 stsp do {
81 a76a38d9 2018-03-11 stsp if (z->avail_in == 0) {
82 a76a38d9 2018-03-11 stsp size_t n = fread(zb->inbuf, 1, zb->inlen, f);
83 a76a38d9 2018-03-11 stsp if (n == 0) {
84 a76a38d9 2018-03-11 stsp if (ferror(f))
85 a76a38d9 2018-03-11 stsp return got_ferror(f, GOT_ERR_IO);
86 92088384 2018-04-01 stsp /* EOF */
87 92088384 2018-04-01 stsp ret = Z_STREAM_END;
88 92088384 2018-04-01 stsp break;
89 a76a38d9 2018-03-11 stsp }
90 a76a38d9 2018-03-11 stsp z->next_in = zb->inbuf;
91 a76a38d9 2018-03-11 stsp z->avail_in = n;
92 a76a38d9 2018-03-11 stsp }
93 a76a38d9 2018-03-11 stsp ret = inflate(z, Z_SYNC_FLUSH);
94 a76a38d9 2018-03-11 stsp } while (ret == Z_OK && z->avail_out > 0);
95 a76a38d9 2018-03-11 stsp
96 a76a38d9 2018-03-11 stsp if (ret == Z_OK) {
97 a76a38d9 2018-03-11 stsp zb->flags |= GOT_ZSTREAM_F_HAVE_MORE;
98 a76a38d9 2018-03-11 stsp } else {
99 a76a38d9 2018-03-11 stsp if (ret != Z_STREAM_END)
100 a76a38d9 2018-03-11 stsp return got_error(GOT_ERR_DECOMPRESSION);
101 a76a38d9 2018-03-11 stsp zb->flags &= ~GOT_ZSTREAM_F_HAVE_MORE;
102 a76a38d9 2018-03-11 stsp }
103 a76a38d9 2018-03-11 stsp
104 a76a38d9 2018-03-11 stsp *outlenp = z->total_out - last_total_out;
105 a76a38d9 2018-03-11 stsp return NULL;
106 a76a38d9 2018-03-11 stsp }
107 a76a38d9 2018-03-11 stsp
108 962916a2 2018-04-24 stsp const struct got_error *
109 962916a2 2018-04-24 stsp got_inflate_read_fd(struct got_zstream_buf *zb, int fd, size_t *outlenp)
110 962916a2 2018-04-24 stsp {
111 962916a2 2018-04-24 stsp size_t last_total_out = zb->z.total_out;
112 962916a2 2018-04-24 stsp z_stream *z = &zb->z;
113 962916a2 2018-04-24 stsp int ret = Z_ERRNO;
114 962916a2 2018-04-24 stsp
115 962916a2 2018-04-24 stsp z->next_out = zb->outbuf;
116 962916a2 2018-04-24 stsp z->avail_out = zb->outlen;
117 962916a2 2018-04-24 stsp
118 962916a2 2018-04-24 stsp *outlenp = 0;
119 962916a2 2018-04-24 stsp do {
120 962916a2 2018-04-24 stsp if (z->avail_in == 0) {
121 962916a2 2018-04-24 stsp ssize_t n = read(fd, zb->inbuf, zb->inlen);
122 962916a2 2018-04-24 stsp if (n < 0)
123 962916a2 2018-04-24 stsp return got_error_from_errno();
124 962916a2 2018-04-24 stsp else if (n == 0) {
125 962916a2 2018-04-24 stsp /* EOF */
126 962916a2 2018-04-24 stsp ret = Z_STREAM_END;
127 962916a2 2018-04-24 stsp break;
128 962916a2 2018-04-24 stsp }
129 962916a2 2018-04-24 stsp z->next_in = zb->inbuf;
130 962916a2 2018-04-24 stsp z->avail_in = n;
131 962916a2 2018-04-24 stsp }
132 962916a2 2018-04-24 stsp ret = inflate(z, Z_SYNC_FLUSH);
133 962916a2 2018-04-24 stsp } while (ret == Z_OK && z->avail_out > 0);
134 962916a2 2018-04-24 stsp
135 962916a2 2018-04-24 stsp if (ret == Z_OK) {
136 962916a2 2018-04-24 stsp zb->flags |= GOT_ZSTREAM_F_HAVE_MORE;
137 962916a2 2018-04-24 stsp } else {
138 962916a2 2018-04-24 stsp if (ret != Z_STREAM_END)
139 962916a2 2018-04-24 stsp return got_error(GOT_ERR_DECOMPRESSION);
140 962916a2 2018-04-24 stsp zb->flags &= ~GOT_ZSTREAM_F_HAVE_MORE;
141 962916a2 2018-04-24 stsp }
142 962916a2 2018-04-24 stsp
143 962916a2 2018-04-24 stsp *outlenp = z->total_out - last_total_out;
144 962916a2 2018-04-24 stsp return NULL;
145 962916a2 2018-04-24 stsp }
146 962916a2 2018-04-24 stsp
147 a76a38d9 2018-03-11 stsp void
148 a76a38d9 2018-03-11 stsp got_inflate_end(struct got_zstream_buf *zb)
149 a76a38d9 2018-03-11 stsp {
150 a76a38d9 2018-03-11 stsp free(zb->inbuf);
151 19d747f7 2018-03-16 stsp if (zb->flags & GOT_ZSTREAM_F_OWN_OUTBUF)
152 19d747f7 2018-03-16 stsp free(zb->outbuf);
153 a76a38d9 2018-03-11 stsp inflateEnd(&zb->z);
154 a76a38d9 2018-03-11 stsp }
155 a76a38d9 2018-03-11 stsp
156 a76a38d9 2018-03-11 stsp const struct got_error *
157 a76a38d9 2018-03-11 stsp got_inflate_to_mem(uint8_t **outbuf, size_t *outlen, FILE *f)
158 a76a38d9 2018-03-11 stsp {
159 a76a38d9 2018-03-11 stsp const struct got_error *err;
160 a76a38d9 2018-03-11 stsp size_t avail;
161 a76a38d9 2018-03-11 stsp struct got_zstream_buf zb;
162 a76a38d9 2018-03-11 stsp void *newbuf;
163 a76a38d9 2018-03-11 stsp
164 19d747f7 2018-03-16 stsp *outbuf = calloc(1, GOT_ZSTREAM_BUFSIZE);
165 19d747f7 2018-03-16 stsp if (*outbuf == NULL)
166 0a585a0d 2018-03-17 stsp return got_error_from_errno();
167 19d747f7 2018-03-16 stsp err = got_inflate_init(&zb, *outbuf, GOT_ZSTREAM_BUFSIZE);
168 a76a38d9 2018-03-11 stsp if (err)
169 a76a38d9 2018-03-11 stsp return err;
170 a76a38d9 2018-03-11 stsp
171 a76a38d9 2018-03-11 stsp *outlen = 0;
172 a76a38d9 2018-03-11 stsp
173 a76a38d9 2018-03-11 stsp do {
174 a76a38d9 2018-03-11 stsp err = got_inflate_read(&zb, f, &avail);
175 a76a38d9 2018-03-11 stsp if (err)
176 a76a38d9 2018-03-11 stsp return err;
177 19d747f7 2018-03-16 stsp *outlen += avail;
178 19d747f7 2018-03-16 stsp if (zb.flags & GOT_ZSTREAM_F_HAVE_MORE) {
179 19d747f7 2018-03-16 stsp newbuf = reallocarray(*outbuf, 1,
180 19d747f7 2018-03-16 stsp *outlen + GOT_ZSTREAM_BUFSIZE);
181 a76a38d9 2018-03-11 stsp if (newbuf == NULL) {
182 0a585a0d 2018-03-17 stsp err = got_error_from_errno();
183 a76a38d9 2018-03-11 stsp free(*outbuf);
184 a76a38d9 2018-03-11 stsp *outbuf = NULL;
185 a76a38d9 2018-03-11 stsp *outlen = 0;
186 a76a38d9 2018-03-11 stsp goto done;
187 a76a38d9 2018-03-11 stsp }
188 a76a38d9 2018-03-11 stsp *outbuf = newbuf;
189 19d747f7 2018-03-16 stsp zb.outbuf = newbuf + *outlen;
190 19d747f7 2018-03-16 stsp zb.outlen = GOT_ZSTREAM_BUFSIZE;
191 a76a38d9 2018-03-11 stsp }
192 a76a38d9 2018-03-11 stsp } while (zb.flags & GOT_ZSTREAM_F_HAVE_MORE);
193 a76a38d9 2018-03-11 stsp
194 a76a38d9 2018-03-11 stsp done:
195 a76a38d9 2018-03-11 stsp got_inflate_end(&zb);
196 a76a38d9 2018-03-11 stsp return err;
197 a76a38d9 2018-03-11 stsp }
198 a76a38d9 2018-03-11 stsp
199 a76a38d9 2018-03-11 stsp const struct got_error *
200 8b2180d4 2018-04-26 stsp got_inflate_to_mem_fd(uint8_t **outbuf, size_t *outlen, int infd)
201 8b2180d4 2018-04-26 stsp {
202 8b2180d4 2018-04-26 stsp const struct got_error *err;
203 8b2180d4 2018-04-26 stsp size_t avail;
204 8b2180d4 2018-04-26 stsp struct got_zstream_buf zb;
205 8b2180d4 2018-04-26 stsp void *newbuf;
206 8b2180d4 2018-04-26 stsp
207 8b2180d4 2018-04-26 stsp *outbuf = calloc(1, GOT_ZSTREAM_BUFSIZE);
208 8b2180d4 2018-04-26 stsp if (*outbuf == NULL)
209 8b2180d4 2018-04-26 stsp return got_error_from_errno();
210 8b2180d4 2018-04-26 stsp err = got_inflate_init(&zb, *outbuf, GOT_ZSTREAM_BUFSIZE);
211 8b2180d4 2018-04-26 stsp if (err)
212 8b2180d4 2018-04-26 stsp return err;
213 8b2180d4 2018-04-26 stsp
214 8b2180d4 2018-04-26 stsp *outlen = 0;
215 8b2180d4 2018-04-26 stsp
216 8b2180d4 2018-04-26 stsp do {
217 8b2180d4 2018-04-26 stsp err = got_inflate_read_fd(&zb, infd, &avail);
218 8b2180d4 2018-04-26 stsp if (err)
219 8b2180d4 2018-04-26 stsp return err;
220 8b2180d4 2018-04-26 stsp *outlen += avail;
221 8b2180d4 2018-04-26 stsp if (zb.flags & GOT_ZSTREAM_F_HAVE_MORE) {
222 8b2180d4 2018-04-26 stsp newbuf = reallocarray(*outbuf, 1,
223 8b2180d4 2018-04-26 stsp *outlen + GOT_ZSTREAM_BUFSIZE);
224 8b2180d4 2018-04-26 stsp if (newbuf == NULL) {
225 8b2180d4 2018-04-26 stsp err = got_error_from_errno();
226 8b2180d4 2018-04-26 stsp free(*outbuf);
227 8b2180d4 2018-04-26 stsp *outbuf = NULL;
228 8b2180d4 2018-04-26 stsp *outlen = 0;
229 8b2180d4 2018-04-26 stsp goto done;
230 8b2180d4 2018-04-26 stsp }
231 8b2180d4 2018-04-26 stsp *outbuf = newbuf;
232 8b2180d4 2018-04-26 stsp zb.outbuf = newbuf + *outlen;
233 8b2180d4 2018-04-26 stsp zb.outlen = GOT_ZSTREAM_BUFSIZE;
234 8b2180d4 2018-04-26 stsp }
235 8b2180d4 2018-04-26 stsp } while (zb.flags & GOT_ZSTREAM_F_HAVE_MORE);
236 8b2180d4 2018-04-26 stsp
237 8b2180d4 2018-04-26 stsp done:
238 8b2180d4 2018-04-26 stsp got_inflate_end(&zb);
239 8b2180d4 2018-04-26 stsp return err;
240 8b2180d4 2018-04-26 stsp }
241 8b2180d4 2018-04-26 stsp
242 8b2180d4 2018-04-26 stsp const struct got_error *
243 8b2180d4 2018-04-26 stsp got_inflate_to_fd(size_t *outlen, FILE *infile, int outfd)
244 962916a2 2018-04-24 stsp {
245 962916a2 2018-04-24 stsp const struct got_error *err = NULL;
246 962916a2 2018-04-24 stsp size_t avail;
247 962916a2 2018-04-24 stsp struct got_zstream_buf zb;
248 962916a2 2018-04-24 stsp
249 962916a2 2018-04-24 stsp err = got_inflate_init(&zb, NULL, GOT_ZSTREAM_BUFSIZE);
250 962916a2 2018-04-24 stsp if (err)
251 962916a2 2018-04-24 stsp goto done;
252 962916a2 2018-04-24 stsp
253 962916a2 2018-04-24 stsp *outlen = 0;
254 962916a2 2018-04-24 stsp
255 962916a2 2018-04-24 stsp do {
256 8b2180d4 2018-04-26 stsp err = got_inflate_read(&zb, infile, &avail);
257 962916a2 2018-04-24 stsp if (err)
258 962916a2 2018-04-24 stsp return err;
259 962916a2 2018-04-24 stsp if (avail > 0) {
260 962916a2 2018-04-24 stsp ssize_t n;
261 962916a2 2018-04-24 stsp n = write(outfd, zb.outbuf, avail);
262 962916a2 2018-04-24 stsp if (n != avail) {
263 962916a2 2018-04-24 stsp err = got_error_from_errno();
264 962916a2 2018-04-24 stsp goto done;
265 962916a2 2018-04-24 stsp }
266 962916a2 2018-04-24 stsp *outlen += avail;
267 962916a2 2018-04-24 stsp }
268 962916a2 2018-04-24 stsp } while (zb.flags & GOT_ZSTREAM_F_HAVE_MORE);
269 962916a2 2018-04-24 stsp
270 962916a2 2018-04-24 stsp done:
271 962916a2 2018-04-24 stsp if (err == NULL) {
272 962916a2 2018-04-24 stsp if (lseek(outfd, SEEK_SET, 0) == -1)
273 962916a2 2018-04-24 stsp err = got_error_from_errno();
274 962916a2 2018-04-24 stsp }
275 962916a2 2018-04-24 stsp got_inflate_end(&zb);
276 962916a2 2018-04-24 stsp return err;
277 962916a2 2018-04-24 stsp }
278 962916a2 2018-04-24 stsp
279 962916a2 2018-04-24 stsp const struct got_error *
280 a76a38d9 2018-03-11 stsp got_inflate_to_file(size_t *outlen, FILE *infile, FILE *outfile)
281 a76a38d9 2018-03-11 stsp {
282 a76a38d9 2018-03-11 stsp const struct got_error *err;
283 a76a38d9 2018-03-11 stsp size_t avail;
284 a76a38d9 2018-03-11 stsp struct got_zstream_buf zb;
285 a76a38d9 2018-03-11 stsp
286 19d747f7 2018-03-16 stsp err = got_inflate_init(&zb, NULL, GOT_ZSTREAM_BUFSIZE);
287 a76a38d9 2018-03-11 stsp if (err)
288 a76a38d9 2018-03-11 stsp goto done;
289 a76a38d9 2018-03-11 stsp
290 a76a38d9 2018-03-11 stsp *outlen = 0;
291 a76a38d9 2018-03-11 stsp
292 a76a38d9 2018-03-11 stsp do {
293 a76a38d9 2018-03-11 stsp err = got_inflate_read(&zb, infile, &avail);
294 a76a38d9 2018-03-11 stsp if (err)
295 a76a38d9 2018-03-11 stsp return err;
296 a76a38d9 2018-03-11 stsp if (avail > 0) {
297 a76a38d9 2018-03-11 stsp size_t n;
298 a76a38d9 2018-03-11 stsp n = fwrite(zb.outbuf, avail, 1, outfile);
299 a76a38d9 2018-03-11 stsp if (n != 1) {
300 a76a38d9 2018-03-11 stsp err = got_ferror(outfile, GOT_ERR_IO);
301 a76a38d9 2018-03-11 stsp goto done;
302 a76a38d9 2018-03-11 stsp }
303 a76a38d9 2018-03-11 stsp *outlen += avail;
304 a76a38d9 2018-03-11 stsp }
305 a76a38d9 2018-03-11 stsp } while (zb.flags & GOT_ZSTREAM_F_HAVE_MORE);
306 a76a38d9 2018-03-11 stsp
307 a76a38d9 2018-03-11 stsp done:
308 a76a38d9 2018-03-11 stsp if (err == NULL)
309 a76a38d9 2018-03-11 stsp rewind(outfile);
310 a76a38d9 2018-03-11 stsp got_inflate_end(&zb);
311 a76a38d9 2018-03-11 stsp return err;
312 a76a38d9 2018-03-11 stsp }
313 8b2180d4 2018-04-26 stsp
314 8b2180d4 2018-04-26 stsp const struct got_error *
315 8b2180d4 2018-04-26 stsp got_inflate_to_file_fd(size_t *outlen, int infd, FILE *outfile)
316 8b2180d4 2018-04-26 stsp {
317 8b2180d4 2018-04-26 stsp const struct got_error *err;
318 8b2180d4 2018-04-26 stsp size_t avail;
319 8b2180d4 2018-04-26 stsp struct got_zstream_buf zb;
320 8b2180d4 2018-04-26 stsp
321 8b2180d4 2018-04-26 stsp err = got_inflate_init(&zb, NULL, GOT_ZSTREAM_BUFSIZE);
322 8b2180d4 2018-04-26 stsp if (err)
323 8b2180d4 2018-04-26 stsp goto done;
324 8b2180d4 2018-04-26 stsp
325 8b2180d4 2018-04-26 stsp *outlen = 0;
326 8b2180d4 2018-04-26 stsp
327 8b2180d4 2018-04-26 stsp do {
328 8b2180d4 2018-04-26 stsp err = got_inflate_read_fd(&zb, infd, &avail);
329 8b2180d4 2018-04-26 stsp if (err)
330 8b2180d4 2018-04-26 stsp return err;
331 8b2180d4 2018-04-26 stsp if (avail > 0) {
332 8b2180d4 2018-04-26 stsp size_t n;
333 8b2180d4 2018-04-26 stsp n = fwrite(zb.outbuf, avail, 1, outfile);
334 8b2180d4 2018-04-26 stsp if (n != 1) {
335 8b2180d4 2018-04-26 stsp err = got_ferror(outfile, GOT_ERR_IO);
336 8b2180d4 2018-04-26 stsp goto done;
337 8b2180d4 2018-04-26 stsp }
338 8b2180d4 2018-04-26 stsp *outlen += avail;
339 8b2180d4 2018-04-26 stsp }
340 8b2180d4 2018-04-26 stsp } while (zb.flags & GOT_ZSTREAM_F_HAVE_MORE);
341 8b2180d4 2018-04-26 stsp
342 8b2180d4 2018-04-26 stsp done:
343 8b2180d4 2018-04-26 stsp if (err == NULL)
344 8b2180d4 2018-04-26 stsp rewind(outfile);
345 8b2180d4 2018-04-26 stsp got_inflate_end(&zb);
346 8b2180d4 2018-04-26 stsp return err;
347 8b2180d4 2018-04-26 stsp }