summaryrefslogtreecommitdiff
path: root/gzio.c
diff options
context:
space:
mode:
Diffstat (limited to 'gzio.c')
-rw-r--r--gzio.c94
1 files changed, 34 insertions, 60 deletions
diff --git a/gzio.c b/gzio.c
index df34620..cf55486 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-2006 Jean-loup Gailly. 2 * Copyright (C) 1995-2009 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.
@@ -71,43 +71,32 @@ static int const gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */
71 71
72typedef struct gz_stream { 72typedef struct gz_stream {
73 z_stream stream; 73 z_stream stream;
74 int z_err; /* error code for last stream operation */ 74 int z_err; /* error code for last stream operation */
75 int z_eof; /* set if end of input file */ 75 int z_eof; /* set if end of input file */
76 FILE *file; /* .gz file */ 76 FILE *file; /* .gz file */
77 Byte *inbuf; /* input buffer */ 77 Byte *inbuf; /* input buffer */
78 Byte *outbuf; /* output buffer */ 78 Byte *outbuf; /* output buffer */
79 uLong crc; /* crc32 of uncompressed data */ 79 uLong crc; /* crc32 of uncompressed data */
80 char *msg; /* error message */ 80 char *msg; /* error message */
81 char *path; /* path name for debugging only */ 81 char *path; /* path name for debugging only */
82 int transparent; /* 1 if input file is not a .gz file */ 82 int transparent; /* 1 if input file is not a .gz file */
83 char mode; /* 'w' or 'r' */ 83 char mode; /* 'w' or 'r' */
84#ifdef _LARGEFILE64_SOURCE 84 z_off64_t start; /* start of compressed data in file */
85 off64_t start; /* start of compressed data in file (header skipped) */ 85 z_off64_t in; /* bytes into deflate or inflate */
86 off64_t in; /* bytes into deflate or inflate */ 86 z_off64_t out; /* bytes out of deflate or inflate */
87 off64_t out; /* bytes out of deflate or inflate */ 87 int back; /* one character push-back */
88#else 88 int last; /* true if push-back is last character */
89 z_off_t start; /* start of compressed data in file (header skipped) */
90 z_off_t in; /* bytes into deflate or inflate */
91 z_off_t out; /* bytes out of deflate or inflate */
92#endif
93 int back; /* one character push-back */
94 int last; /* true if push-back is last character */
95} gz_stream; 89} gz_stream;
96 90
97 91
98local gzFile gz_open OF((const char *path, const char *mode, int fd, 92local gzFile gz_open OF((const char *, const char *, int, int));
99 int use64)); 93local z_off64_t gz_seek OF((gzFile, z_off64_t, int, int));
100#ifdef _LARGEFILE64_SOURCE 94local int do_flush OF((gzFile, int));
101local off64_t gz_seek OF((gzFile file, off64_t offset, int whence, int use64)); 95local int get_byte OF((gz_stream *));
102#else 96local void check_header OF((gz_stream *));
103local z_off_t gz_seek OF((gzFile file, z_off_t offset, int whence, int use64)); 97local int destroy OF((gz_stream *));
104#endif 98local void putLong OF((FILE *, uLong));
105local int do_flush OF((gzFile file, int flush)); 99local uLong getLong OF((gz_stream *));
106local int get_byte OF((gz_stream *s));
107local void check_header OF((gz_stream *s));
108local int destroy OF((gz_stream *s));
109local void putLong OF((FILE *file, uLong x));
110local uLong getLong OF((gz_stream *s));
111 100
112/* =========================================================================== 101/* ===========================================================================
113 Opens a gzip (.gz) file for reading or writing. The mode parameter 102 Opens a gzip (.gz) file for reading or writing. The mode parameter
@@ -143,6 +132,7 @@ local gzFile gz_open (path, mode, fd, use64)
143 s->stream.next_in = s->inbuf = Z_NULL; 132 s->stream.next_in = s->inbuf = Z_NULL;
144 s->stream.next_out = s->outbuf = Z_NULL; 133 s->stream.next_out = s->outbuf = Z_NULL;
145 s->stream.avail_in = s->stream.avail_out = 0; 134 s->stream.avail_in = s->stream.avail_out = 0;
135 s->stream.state = Z_NULL;
146 s->file = NULL; 136 s->file = NULL;
147 s->z_err = Z_OK; 137 s->z_err = Z_OK;
148 s->z_eof = 0; 138 s->z_eof = 0;
@@ -442,7 +432,7 @@ int ZEXPORT gzread (file, buf, len)
442 if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR; 432 if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR;
443 433
444 if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO) return -1; 434 if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO) return -1;
445 if (s->z_err == Z_STREAM_END) return 0; /* EOF */ 435 if (s->z_err == Z_STREAM_END || s->z_eof) return 0; /* EOF */
446 436
447 next_out = (Byte*)buf; 437 next_out = (Byte*)buf;
448 s->stream.next_out = (Bytef*)buf; 438 s->stream.next_out = (Bytef*)buf;
@@ -482,7 +472,7 @@ int ZEXPORT gzread (file, buf, len)
482 len -= s->stream.avail_out; 472 len -= s->stream.avail_out;
483 s->in += len; 473 s->in += len;
484 s->out += len; 474 s->out += len;
485 if (len == 0) s->z_eof = 1; 475 if (feof(s->file)) s->z_eof = 1;
486 return (int)len; 476 return (int)len;
487 } 477 }
488 if (s->stream.avail_in == 0 && !s->z_eof) { 478 if (s->stream.avail_in == 0 && !s->z_eof) {
@@ -803,15 +793,9 @@ int ZEXPORT gzflush (file, flush)
803 SEEK_END is not implemented, returns error. 793 SEEK_END is not implemented, returns error.
804 In this version of the library, gzseek can be extremely slow. 794 In this version of the library, gzseek can be extremely slow.
805*/ 795*/
806#ifdef _LARGEFILE64_SOURCE 796local z_off64_t gz_seek (file, offset, whence, use64)
807local off64_t gz_seek (file, offset, whence, use64)
808 gzFile file;
809 off64_t offset;
810#else
811local z_off_t gz_seek (file, offset, whence, use64)
812 gzFile file; 797 gzFile file;
813 z_off_t offset; 798 z_off64_t offset;
814#endif
815 int whence; 799 int whence;
816 int use64; 800 int use64;
817{ 801{
@@ -914,23 +898,17 @@ z_off_t ZEXPORT gzseek (file, offset, whence)
914 return (z_off_t)gz_seek(file, offset, whence, 0); 898 return (z_off_t)gz_seek(file, offset, whence, 0);
915} 899}
916 900
917#ifdef _LARGEFILE64_SOURCE 901z_off64_t ZEXPORT gzseek64 (file, offset, whence)
918off64_t ZEXPORT gzseek64 (file, offset, whence)
919 gzFile file; 902 gzFile file;
920 off64_t offset; 903 z_off64_t offset;
921 int whence; 904 int whence;
922{ 905{
906#ifdef _LARGEFILE64_SOURCE
923 return gz_seek(file, offset, whence, 1); 907 return gz_seek(file, offset, whence, 1);
924}
925#else 908#else
926z_off_t ZEXPORT gzseek64 (file, offset, whence)
927 gzFile file;
928 z_off_t offset;
929 int whence;
930{
931 return gz_seek(file, offset, whence, 0); 909 return gz_seek(file, offset, whence, 0);
932}
933#endif 910#endif
911}
934 912
935/* =========================================================================== 913/* ===========================================================================
936 Rewinds input file. 914 Rewinds input file.
@@ -968,11 +946,7 @@ z_off_t ZEXPORT gztell (file)
968/* =========================================================================== 946/* ===========================================================================
969 64-bit version 947 64-bit version
970*/ 948*/
971#ifdef _LARGEFILE64_SOURCE 949z_off64_t ZEXPORT gztell64 (file)
972off64_t ZEXPORT gztell64 (file)
973#else
974z_off_t ZEXPORT gztell64 (file)
975#endif
976 gzFile file; 950 gzFile file;
977{ 951{
978 return gzseek64(file, 0L, SEEK_CUR); 952 return gzseek64(file, 0L, SEEK_CUR);