/* 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.
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)
/* ===========================================================================
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)
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)
/* ===========================================================================
* 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)
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)
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)
* 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)
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)
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;
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)
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)
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)
}
#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)
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)
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)
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)
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)
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)
return -1L;
#else
if (whence == SEEK_SET) {
- offset -= s->stream.total_out;
+ offset -= s->stream.total_in;
}
if (offset < 0) return -1L;
/* ===========================================================================
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)
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);
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)
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)
/* ===========================================================================
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)
}
/* ===========================================================================
- 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)
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)
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)