gzipfs.c (123392) | gzipfs.c (124811) |
---|---|
1/* 2 * Copyright (c) 1998 Michael Smith. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/* 2 * Copyright (c) 1998 Michael Smith. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/lib/libstand/gzipfs.c 123392 2003-12-10 16:10:34Z green $"); | 28__FBSDID("$FreeBSD: head/lib/libstand/gzipfs.c 124811 2004-01-21 20:12:23Z jhb $"); |
29 30#include "stand.h" 31 32#include <sys/stat.h> 33#include <string.h> 34#include <zlib.h> 35 36#define Z_BUFSIZE 2048 /* XXX larger? */ --- 213 unchanged lines hidden (view full) --- 250 int error; 251 252 zf->zf_zstream.next_out = buf; /* where and how much */ 253 zf->zf_zstream.avail_out = size; 254 255 while (zf->zf_zstream.avail_out) { 256 if ((zf->zf_zstream.avail_in == 0) && (zf_fill(zf) == -1)) { 257 printf("zf_read: fill error\n"); | 29 30#include "stand.h" 31 32#include <sys/stat.h> 33#include <string.h> 34#include <zlib.h> 35 36#define Z_BUFSIZE 2048 /* XXX larger? */ --- 213 unchanged lines hidden (view full) --- 250 int error; 251 252 zf->zf_zstream.next_out = buf; /* where and how much */ 253 zf->zf_zstream.avail_out = size; 254 255 while (zf->zf_zstream.avail_out) { 256 if ((zf->zf_zstream.avail_in == 0) && (zf_fill(zf) == -1)) { 257 printf("zf_read: fill error\n"); |
258 return(-1); | 258 return(EIO); |
259 } 260 if (zf->zf_zstream.avail_in == 0) { /* oops, unexpected EOF */ 261 printf("zf_read: unexpected EOF\n"); | 259 } 260 if (zf->zf_zstream.avail_in == 0) { /* oops, unexpected EOF */ 261 printf("zf_read: unexpected EOF\n"); |
262 if (zf->zf_zstream.avail_out == size) 263 return (EIO); |
|
262 break; 263 } 264 265 error = inflate(&zf->zf_zstream, Z_SYNC_FLUSH); /* decompression pass */ 266 if (error == Z_STREAM_END) { /* EOF, all done */ 267 break; 268 } 269 if (error != Z_OK) { /* argh, decompression error */ 270 printf("inflate: %s\n", zf->zf_zstream.msg); | 264 break; 265 } 266 267 error = inflate(&zf->zf_zstream, Z_SYNC_FLUSH); /* decompression pass */ 268 if (error == Z_STREAM_END) { /* EOF, all done */ 269 break; 270 } 271 if (error != Z_OK) { /* argh, decompression error */ 272 printf("inflate: %s\n", zf->zf_zstream.msg); |
271 errno = EIO; 272 return(-1); | 273 return(EIO); |
273 } 274 } 275 if (resid != NULL) 276 *resid = zf->zf_zstream.avail_out; 277 return(0); 278} 279 280static int --- 19 unchanged lines hidden (view full) --- 300 301 switch (where) { 302 case SEEK_SET: 303 target = offset; 304 break; 305 case SEEK_CUR: 306 target = offset + zf->zf_zstream.total_out; 307 break; | 274 } 275 } 276 if (resid != NULL) 277 *resid = zf->zf_zstream.avail_out; 278 return(0); 279} 280 281static int --- 19 unchanged lines hidden (view full) --- 301 302 switch (where) { 303 case SEEK_SET: 304 target = offset; 305 break; 306 case SEEK_CUR: 307 target = offset + zf->zf_zstream.total_out; 308 break; |
308 default: | 309 case SEEK_END: |
309 target = -1; | 310 target = -1; |
311 default: 312 errno = EINVAL; 313 return (-1); |
|
310 } 311 312 /* rewind if required */ 313 if (target < zf->zf_zstream.total_out && zf_rewind(f) != 0) 314 return -1; 315 316 /* skip forwards if required */ 317 while (target > zf->zf_zstream.total_out) { | 314 } 315 316 /* rewind if required */ 317 if (target < zf->zf_zstream.total_out && zf_rewind(f) != 0) 318 return -1; 319 320 /* skip forwards if required */ 321 while (target > zf->zf_zstream.total_out) { |
318 if (zf_read(f, discard, min(sizeof(discard), target - zf->zf_zstream.total_out), NULL) == -1) | 322 errno = zf_read(f, discard, min(sizeof(discard), 323 target - zf->zf_zstream.total_out), NULL); 324 if (errno) |
319 return(-1); 320 } 321 /* This is where we are (be honest if we overshot) */ 322 return (zf->zf_zstream.total_out); 323} 324 325 326static int --- 13 unchanged lines hidden --- | 325 return(-1); 326 } 327 /* This is where we are (be honest if we overshot) */ 328 return (zf->zf_zstream.total_out); 329} 330 331 332static int --- 13 unchanged lines hidden --- |