X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e6ebb51430cd8e4a9a11c6c5a5ca7c3ff9d7a72a..02a8e64ca3a617d776e6e5f881f915aadbd47c4c:/src/zlib/gzio.c diff --git a/src/zlib/gzio.c b/src/zlib/gzio.c index 868d218844..7c80e9c5b2 100644 --- a/src/zlib/gzio.c +++ b/src/zlib/gzio.c @@ -1,5 +1,5 @@ /* gzio.c -- IO on .gz files - * Copyright (C) 1995-1998 Jean-loup Gailly. + * Copyright (C) 1995-2002 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h * * Compile this file with -DNO_DEFLATE to avoid the compression code. @@ -70,7 +70,7 @@ local uLong getLong OF((gz_stream *s)); can be checked to distinguish the two cases (if errno is zero, the zlib error is Z_MEM_ERROR). */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ local gzFile gz_open (const char* path, const char* mode, int fd) #else local gzFile gz_open (path, mode, fd) @@ -184,7 +184,7 @@ local gzFile gz_open (path, mode, fd) /* =========================================================================== Opens a gzip (.gz) file for reading or writing. */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ gzFile ZEXPORT gzopen (const char* path, const char* mode) #else gzFile ZEXPORT gzopen (path, mode) @@ -199,7 +199,7 @@ gzFile ZEXPORT gzopen (path, mode) Associate a gzFile with the file descriptor fd. fd is not dup'ed here to mimic the behavio(u)r of fdopen. */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ gzFile ZEXPORT gzdopen (int fd, const char* mode) #else gzFile ZEXPORT gzdopen (fd, mode) @@ -218,7 +218,7 @@ gzFile ZEXPORT gzdopen (fd, mode) /* =========================================================================== * Update the compression level and strategy */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ int ZEXPORT gzsetparams (gzFile file, int level, int strategy) #else int ZEXPORT gzsetparams (file, level, strategy) @@ -249,7 +249,7 @@ int ZEXPORT gzsetparams (file, level, strategy) for end of file. IN assertion: the stream s has been sucessfully opened for reading. */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ local int get_byte(gz_stream* s) #else local int get_byte(s) @@ -280,7 +280,7 @@ local int get_byte(s) s->stream.avail_in is zero for the first time, but may be non-zero for concatenated .gz files. */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ local void check_header(gz_stream* s) #else local void check_header(s) @@ -337,7 +337,7 @@ local void check_header(s) * Cleanup then free the given gz_stream. Return a zlib error code. Try freeing in the reverse order of allocations. */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ local int destroy (gz_stream* s) #else local int destroy (s) @@ -380,7 +380,7 @@ local int destroy (s) Reads the given number of uncompressed bytes from the compressed file. gzread returns the number of bytes actually read (0 for end of file). */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ int ZEXPORT gzread (gzFile file, voidp buf, unsigned len) #else int ZEXPORT gzread (file, buf, len) @@ -446,10 +446,14 @@ int ZEXPORT gzread (file, buf, len) s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start)); start = s->stream.next_out; - if (getLong(s) != s->crc || getLong(s) != s->stream.total_out) { + if (getLong(s) != s->crc) { s->z_err = Z_DATA_ERROR; } else { - /* Check for concatenated .gz files: */ + (void)getLong(s); + /* The uncompressed length returned by above getlong() may + * be different from s->stream.total_out) in case of + * concatenated .gz files. Check for such files: + */ check_header(s); if (s->z_err == Z_OK) { uLong total_in = s->stream.total_in; @@ -474,7 +478,7 @@ int ZEXPORT gzread (file, buf, len) Reads one byte from the compressed file. gzgetc returns this byte or -1 in case of end of file or error. */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ int ZEXPORT gzgetc(gzFile file) #else int ZEXPORT gzgetc(file) @@ -496,7 +500,7 @@ int ZEXPORT gzgetc(file) The current implementation is not optimized at all. */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ char* ZEXPORT gzgets(gzFile file, char* buf, int len) #else char * ZEXPORT gzgets(file, buf, len) @@ -519,7 +523,7 @@ char * ZEXPORT gzgets(file, buf, len) Writes the given number of uncompressed bytes into the compressed file. gzwrite returns the number of bytes actually written (0 in case of error). */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ int ZEXPORT gzwrite (gzFile file, const voidp buf, unsigned len) #else int ZEXPORT gzwrite (file, buf, len) @@ -582,7 +586,7 @@ int ZEXPORTVA gzprintf (gzFile file, const char *format, /* args */ ...) } #else /* not ANSI C */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ int ZEXPORTVA gzprintf (gzFile file const char* format, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10, int a11, int a12 int a13, int a14, int a15, int a16, int a17, int a18, int a19, int a20) @@ -616,7 +620,7 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, Writes c, converted to an unsigned char, into the compressed file. gzputc returns the value that was written, or -1 in case of error. */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ int ZEXPORT gzputc(gzFile file, int c) #else int ZEXPORT gzputc(file, c) @@ -635,7 +639,7 @@ int ZEXPORT gzputc(file, c) the terminating null character. gzputs returns the number of characters written, or -1 in case of error. */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ int ZEXPORT gzputs(gzFile file, const char* s) #else int ZEXPORT gzputs(file, s) @@ -651,7 +655,7 @@ int ZEXPORT gzputs(file, s) Flushes all pending output into the compressed file. The parameter flush is as in the deflate() function. */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ local int do_flush (gzFile file, int flush) #else local int do_flush (file, flush) @@ -694,7 +698,7 @@ local int do_flush (file, flush) return s->z_err == Z_STREAM_END ? Z_OK : s->z_err; } -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ int ZEXPORT gzflush (gzFile file, int flush) #else int ZEXPORT gzflush (file, flush) @@ -719,7 +723,7 @@ int ZEXPORT gzflush (file, flush) SEEK_END is not implemented, returns error. In this version of the library, gzseek can be extremely slow. */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ z_off_t ZEXPORT gzseek (gzFile file, z_off_t offset, int whence) #else z_off_t ZEXPORT gzseek (file, offset, whence) @@ -740,7 +744,7 @@ z_off_t ZEXPORT gzseek (file, offset, whence) return -1L; #else if (whence == SEEK_SET) { - offset -= s->stream.total_out; + offset -= s->stream.total_in; } if (offset < 0) return -1L; @@ -804,7 +808,7 @@ z_off_t ZEXPORT gzseek (file, offset, whence) /* =========================================================================== Rewinds input file. */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ int ZEXPORT gzrewind (gzFile file) #else int ZEXPORT gzrewind (file) @@ -819,6 +823,7 @@ int ZEXPORT gzrewind (file) s->z_eof = 0; s->stream.avail_in = 0; s->stream.next_in = s->inbuf; + s->crc = crc32(0L, Z_NULL, 0); if (s->startpos == 0) { /* not a compressed file */ rewind(s->file); @@ -834,7 +839,7 @@ int ZEXPORT gzrewind (file) given compressed file. This position represents a number of bytes in the uncompressed data stream. */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ z_off_t ZEXPORT gztell (gzFile file) #else z_off_t ZEXPORT gztell (file) @@ -848,7 +853,7 @@ z_off_t ZEXPORT gztell (file) Returns 1 when EOF has previously been detected reading the given input stream, otherwise zero. */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ int ZEXPORT gzeof (gzFile file) #else int ZEXPORT gzeof (file) @@ -863,7 +868,7 @@ int ZEXPORT gzeof (file) /* =========================================================================== Outputs a long in LSB order to the given file */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ local void putLong (FILE* file, uLong x) #else local void putLong (file, x) @@ -879,9 +884,10 @@ local void putLong (file, x) } /* =========================================================================== - Reads a long in LSB order from the given gz_stream. Sets + Reads a long in LSB order from the given gz_stream. Sets z_err in case + of error. */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ local uLong getLong (gz_stream* s) #else local uLong getLong (s) @@ -903,7 +909,7 @@ local uLong getLong (s) Flushes all pending output if necessary, closes the compressed file and deallocates all the (de)compression state. */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ int ZEXPORT gzclose (gzFile file) #else int ZEXPORT gzclose (file) @@ -936,7 +942,7 @@ int ZEXPORT gzclose (file) errnum is set to Z_ERRNO and the application may consult errno to get the exact error code. */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ const char* ZEXPORT gzerror (gzFile file, int* errnum) #else const char* ZEXPORT gzerror (file, errnum)