From 8198f694f52b6a6284069a37b44bcce5847acdf2 Mon Sep 17 00:00:00 2001 From: Ralf Corsepius Date: Fri, 18 Mar 2011 10:10:55 +0000 Subject: Import zlib-1.2.3 --- cpukit/zlib/gzio.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'cpukit/zlib/gzio.c') diff --git a/cpukit/zlib/gzio.c b/cpukit/zlib/gzio.c index 217a4cc410..7e90f4928f 100644 --- a/cpukit/zlib/gzio.c +++ b/cpukit/zlib/gzio.c @@ -1,5 +1,5 @@ /* gzio.c -- IO on .gz files - * Copyright (C) 1995-2004 Jean-loup Gailly. + * Copyright (C) 1995-2005 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h * * Compile this file with -DNO_GZCOMPRESS to avoid the compression code. @@ -264,7 +264,7 @@ local int get_byte(s) if (s->z_eof) return EOF; if (s->stream.avail_in == 0) { errno = 0; - s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file); + s->stream.avail_in = (uInt)fread(s->inbuf, 1, Z_BUFSIZE, s->file); if (s->stream.avail_in == 0) { s->z_eof = 1; if (ferror(s->file)) s->z_err = Z_ERRNO; @@ -300,7 +300,7 @@ local void check_header(s) if (len < 2) { if (len) s->inbuf[0] = s->stream.next_in[0]; errno = 0; - len = fread(s->inbuf + len, 1, Z_BUFSIZE >> len, s->file); + len = (uInt)fread(s->inbuf + len, 1, Z_BUFSIZE >> len, s->file); if (len == 0 && ferror(s->file)) s->z_err = Z_ERRNO; s->stream.avail_in += len; s->stream.next_in = s->inbuf; @@ -415,6 +415,7 @@ int ZEXPORT gzread (file, buf, len) s->stream.avail_out--; s->back = EOF; s->out++; + start++; if (s->last) { s->z_err = Z_STREAM_END; return 1; @@ -436,8 +437,8 @@ int ZEXPORT gzread (file, buf, len) s->stream.avail_in -= n; } if (s->stream.avail_out > 0) { - s->stream.avail_out -= fread(next_out, 1, s->stream.avail_out, - s->file); + s->stream.avail_out -= + (uInt)fread(next_out, 1, s->stream.avail_out, s->file); } len -= s->stream.avail_out; s->in += len; @@ -448,17 +449,13 @@ int ZEXPORT gzread (file, buf, len) if (s->stream.avail_in == 0 && !s->z_eof) { errno = 0; - s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file); + s->stream.avail_in = (uInt)fread(s->inbuf, 1, Z_BUFSIZE, s->file); if (s->stream.avail_in == 0) { s->z_eof = 1; if (ferror(s->file)) { s->z_err = Z_ERRNO; break; } - if (feof(s->file)) { /* avoid error for empty file */ - s->z_err = Z_STREAM_END; - break; - } } s->stream.next_in = s->inbuf; } @@ -492,6 +489,9 @@ int ZEXPORT gzread (file, buf, len) } s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start)); + if (len == s->stream.avail_out && + (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO)) + return -1; return (int)(len - s->stream.avail_out); } @@ -902,6 +902,18 @@ int ZEXPORT gzeof (file) return s->z_err == Z_STREAM_END; } +/* =========================================================================== + Returns 1 if reading and doing so transparently, otherwise zero. +*/ +int ZEXPORT gzdirect (file) + gzFile file; +{ + gz_stream *s = (gz_stream*)file; + + if (s == NULL || s->mode != 'r') return 0; + return s->transparent; +} + /* =========================================================================== Outputs a long in LSB order to the given file */ @@ -966,9 +978,9 @@ int ZEXPORT gzclose (file) #endif /* =========================================================================== - Returns the error message for the last error which occured on the + Returns the error message for the last error which occurred on the given compressed file. errnum is set to zlib error number. If an - error occured in the file system and not in the compression library, + error occurred in the file system and not in the compression library, errnum is set to Z_ERRNO and the application may consult errno to get the exact error code. */ -- cgit v1.2.3