summaryrefslogtreecommitdiff
path: root/gzio.c
diff options
context:
space:
mode:
Diffstat (limited to 'gzio.c')
-rw-r--r--gzio.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/gzio.c b/gzio.c
index 7e90f49..a8130ef 100644
--- a/gzio.c
+++ b/gzio.c
@@ -1,5 +1,5 @@
1/* gzio.c -- IO on .gz files 1/* gzio.c -- IO on .gz files
2 * Copyright (C) 1995-2005 Jean-loup Gailly. 2 * Copyright (C) 1995-2006 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 * 4 *
5 * Compile this file with -DNO_GZCOMPRESS to avoid the compression code. 5 * Compile this file with -DNO_GZCOMPRESS to avoid the compression code.
@@ -7,9 +7,8 @@
7 7
8/* @(#) $Id$ */ 8/* @(#) $Id$ */
9 9
10#include <stdio.h>
11
12#include "zutil.h" 10#include "zutil.h"
11#include <stdio.h>
13 12
14#ifdef NO_DEFLATE /* for compatibility with old definition */ 13#ifdef NO_DEFLATE /* for compatibility with old definition */
15# define NO_GZCOMPRESS 14# define NO_GZCOMPRESS
@@ -187,7 +186,10 @@ local gzFile gz_open (path, mode, fd)
187 /* Write a very simple .gz header: 186 /* Write a very simple .gz header:
188 */ 187 */
189 fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1], 188 fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1],
190 Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE); 189 Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, level == 9 ? 2 :
190 (strategy >= Z_HUFFMAN_ONLY ||
191 (level != Z_DEFAULT_COMPRESSION && level < 2) ?
192 4 : 0) /*xflags*/, OS_CODE);
191 s->start = 10L; 193 s->start = 10L;
192 /* We use 10L instead of ftell(s->file) to because ftell causes an 194 /* We use 10L instead of ftell(s->file) to because ftell causes an
193 * fflush on some systems. This version of the library doesn't use 195 * fflush on some systems. This version of the library doesn't use
@@ -256,7 +258,7 @@ int ZEXPORT gzsetparams (file, level, strategy)
256/* =========================================================================== 258/* ===========================================================================
257 Read a byte from a gz_stream; update next_in and avail_in. Return EOF 259 Read a byte from a gz_stream; update next_in and avail_in. Return EOF
258 for end of file. 260 for end of file.
259 IN assertion: the stream s has been sucessfully opened for reading. 261 IN assertion: the stream s has been successfully opened for reading.
260*/ 262*/
261local int get_byte(s) 263local int get_byte(s)
262 gz_stream *s; 264 gz_stream *s;
@@ -281,7 +283,7 @@ local int get_byte(s)
281 mode to transparent if the gzip magic header is not present; set s->err 283 mode to transparent if the gzip magic header is not present; set s->err
282 to Z_DATA_ERROR if the magic header is present but the rest of the header 284 to Z_DATA_ERROR if the magic header is present but the rest of the header
283 is incorrect. 285 is incorrect.
284 IN assertion: the stream s has already been created sucessfully; 286 IN assertion: the stream s has already been created successfully;
285 s->stream.avail_in is zero for the first time, but may be non-zero 287 s->stream.avail_in is zero for the first time, but may be non-zero
286 for concatenated .gz files. 288 for concatenated .gz files.
287*/ 289*/
@@ -301,6 +303,7 @@ local void check_header(s)
301 if (len) s->inbuf[0] = s->stream.next_in[0]; 303 if (len) s->inbuf[0] = s->stream.next_in[0];
302 errno = 0; 304 errno = 0;
303 len = (uInt)fread(s->inbuf + len, 1, Z_BUFSIZE >> len, s->file); 305 len = (uInt)fread(s->inbuf + len, 1, Z_BUFSIZE >> len, s->file);
306 if (len == 0) s->z_eof = 1;
304 if (len == 0 && ferror(s->file)) s->z_err = Z_ERRNO; 307 if (len == 0 && ferror(s->file)) s->z_err = Z_ERRNO;
305 s->stream.avail_in += len; 308 s->stream.avail_in += len;
306 s->stream.next_in = s->inbuf; 309 s->stream.next_in = s->inbuf;
@@ -436,7 +439,7 @@ int ZEXPORT gzread (file, buf, len)
436 s->stream.avail_out -= n; 439 s->stream.avail_out -= n;
437 s->stream.avail_in -= n; 440 s->stream.avail_in -= n;
438 } 441 }
439 if (s->stream.avail_out > 0) { 442 if (s->stream.avail_out > 0 && !feof(s->file)) {
440 s->stream.avail_out -= 443 s->stream.avail_out -=
441 (uInt)fread(next_out, 1, s->stream.avail_out, s->file); 444 (uInt)fread(next_out, 1, s->stream.avail_out, s->file);
442 } 445 }
@@ -971,7 +974,7 @@ int ZEXPORT gzclose (file)
971 return destroy((gz_stream*)file); 974 return destroy((gz_stream*)file);
972} 975}
973 976
974#ifdef STDC 977#if defined(STDC) && !defined(_WIN32_WCE)
975# define zstrerror(errnum) strerror(errnum) 978# define zstrerror(errnum) strerror(errnum)
976#else 979#else
977# define zstrerror(errnum) "" 980# define zstrerror(errnum) ""