diff options
author | jhb <jhb@FreeBSD.org> | 2004-01-21 20:12:23 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2004-01-21 20:12:23 +0000 |
commit | fffc52fe7a3393e38603b6d028c721e38a1d1cc3 (patch) | |
tree | ef59111118b96cb170e58b13a12c868718248613 /lib/libstand/gzipfs.c | |
parent | c6b7068a7d44e6082f3cba1e19415d67838013ac (diff) | |
download | FreeBSD-src-fffc52fe7a3393e38603b6d028c721e38a1d1cc3.zip FreeBSD-src-fffc52fe7a3393e38603b6d028c721e38a1d1cc3.tar.gz |
Clean up error handling in libstand filesystem code to be more consistent:
- bzipfs and gzipfs now properly return errno values directly from their
read routines rather than returning -1.
- missing errno values on error returns for the seek routines on almost
all filesystems were added.
- fstat() now returns -1 if an error occurs rather than ignoring it.
- nfs's readdir() routine now reports valid errno values if an error or
EOF occurs rather than EPERM (It was just returning 0 for success and
1 for failure).
- nullfs used the wrong semantics for every function besides close() and
seek(). Getting it right for close() appears to be an accident at that.
- read() for buffered files no longer returns 0 (EOF) if an error occurs,
but returns -1 instead.
Diffstat (limited to 'lib/libstand/gzipfs.c')
-rw-r--r-- | lib/libstand/gzipfs.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/libstand/gzipfs.c b/lib/libstand/gzipfs.c index 9cc9ad9..0d7c59b 100644 --- a/lib/libstand/gzipfs.c +++ b/lib/libstand/gzipfs.c @@ -255,10 +255,12 @@ zf_read(struct open_file *f, void *buf, size_t size, size_t *resid) while (zf->zf_zstream.avail_out) { if ((zf->zf_zstream.avail_in == 0) && (zf_fill(zf) == -1)) { printf("zf_read: fill error\n"); - return(-1); + return(EIO); } if (zf->zf_zstream.avail_in == 0) { /* oops, unexpected EOF */ printf("zf_read: unexpected EOF\n"); + if (zf->zf_zstream.avail_out == size) + return (EIO); break; } @@ -268,8 +270,7 @@ zf_read(struct open_file *f, void *buf, size_t size, size_t *resid) } if (error != Z_OK) { /* argh, decompression error */ printf("inflate: %s\n", zf->zf_zstream.msg); - errno = EIO; - return(-1); + return(EIO); } } if (resid != NULL) @@ -305,8 +306,11 @@ zf_seek(struct open_file *f, off_t offset, int where) case SEEK_CUR: target = offset + zf->zf_zstream.total_out; break; - default: + case SEEK_END: target = -1; + default: + errno = EINVAL; + return (-1); } /* rewind if required */ @@ -315,7 +319,9 @@ zf_seek(struct open_file *f, off_t offset, int where) /* skip forwards if required */ while (target > zf->zf_zstream.total_out) { - if (zf_read(f, discard, min(sizeof(discard), target - zf->zf_zstream.total_out), NULL) == -1) + errno = zf_read(f, discard, min(sizeof(discard), + target - zf->zf_zstream.total_out), NULL); + if (errno) return(-1); } /* This is where we are (be honest if we overshot) */ |