diff options
author | Guy Harris <guy@alum.mit.edu> | 2002-06-07 07:27:35 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2002-06-07 07:27:35 +0000 |
commit | 2aad75bb826b45ee1a78be2bbe2687e488748f8b (patch) | |
tree | fc165ec22e943d3b15a10b6c8c84359286432e05 /wiretap/file_wrappers.c | |
parent | c15486768a2d90fcf97ca8ea628f3d174ad11a5b (diff) | |
download | wireshark-2aad75bb826b45ee1a78be2bbe2687e488748f8b.tar.gz |
Graeme Hewson noted that zlib has a bug wherein "gzseek()" doesn't set
the internal z_err value for the stream if an "fseek()" call it makes
fails, so that if "gzerror()" is subsequently called, it returns Z_OK
rather than an error.
To work around this, we pass "file_seek()" an "int *err", and have the
with-zlib version of "file_seek()" check, if "gzseek()" fails, whether
the return value of "file_error()" is 0 and, if so, have it return
"errno" instead.
svn path=/trunk/; revision=5642
Diffstat (limited to 'wiretap/file_wrappers.c')
-rw-r--r-- | wiretap/file_wrappers.c | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/wiretap/file_wrappers.c b/wiretap/file_wrappers.c index c69a00daac..ae8a98706d 100644 --- a/wiretap/file_wrappers.c +++ b/wiretap/file_wrappers.c @@ -1,6 +1,6 @@ /* file_wrappers.c * - * $Id: file_wrappers.c,v 1.10 2002/02/06 09:58:30 guy Exp $ + * $Id: file_wrappers.c,v 1.11 2002/06/07 07:27:34 guy Exp $ * * Wiretap Library * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu> @@ -104,9 +104,26 @@ #ifdef HAVE_LIBZ long -file_seek(void *stream, long offset, int whence) +file_seek(void *stream, long offset, int whence, int *err) { - return gzseek(stream, (z_off_t)offset, whence); + long ret; + + ret = gzseek(stream, (z_off_t)offset, whence); + if (ret == -1) { + /* + * XXX - "gzseek()", as of zlib 1.1.4, doesn't set + * "z_err" for the stream, so "gzerror()" could return + * a bogus Z_OK. + * + * As this call failed, we know "gzerror()" shouldn't + * return Z_OK; if it does, we assume that "errno" is + * the real error. + */ + *err = file_error(stream); + if (*err == 0) + *err = errno; + } + return ret; } long @@ -114,6 +131,17 @@ file_tell(void *stream) { return (long)gztell(stream); } +#else /* HAVE_LIBZ */ +long +file_seek(void *stream, long offset, int whence, int *err) +{ + long ret; + + ret = fseek(stream, offset, whence); + if (ret == -1) + *err = file_error(stream); + return ret; +} #endif /* HAVE_LIBZ */ /* |