summaryrefslogtreecommitdiff
path: root/gzlib.c
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2011-09-09 23:27:08 -0700
committerMark Adler <madler@alumni.caltech.edu>2011-09-09 23:27:08 -0700
commit7df877eccdd826e94df53215f65dee639428e83f (patch)
tree11ed5070798961e28a4c69d9272ecaada500abc3 /gzlib.c
parentdc5a43ebfadb6b775f6e64bfeb5a461c66acb394 (diff)
downloadzlib-7df877eccdd826e94df53215f65dee639428e83f.tar.gz
zlib-7df877eccdd826e94df53215f65dee639428e83f.tar.bz2
zlib-7df877eccdd826e94df53215f65dee639428e83f.zip
zlib 1.2.3.7v1.2.3.7
Diffstat (limited to 'gzlib.c')
-rw-r--r--gzlib.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/gzlib.c b/gzlib.c
index c9a82dc..e637e83 100644
--- a/gzlib.c
+++ b/gzlib.c
@@ -15,7 +15,7 @@
15 15
16/* Local functions */ 16/* Local functions */
17local void gz_reset OF((gz_statep)); 17local void gz_reset OF((gz_statep));
18local gzFile gz_open OF((const char *, int, const char *, int)); 18local gzFile gz_open OF((const char *, int, const char *));
19 19
20#if defined UNDER_CE && defined NO_ERRNO_H 20#if defined UNDER_CE && defined NO_ERRNO_H
21 21
@@ -73,10 +73,11 @@ char ZEXPORT *gz_strwinerror (error)
73local void gz_reset(state) 73local void gz_reset(state)
74 gz_statep state; 74 gz_statep state;
75{ 75{
76 state->how = 0; /* look for gzip header */
77 if (state->mode == GZ_READ) { /* for reading ... */ 76 if (state->mode == GZ_READ) { /* for reading ... */
78 state->have = 0; /* no output data available */ 77 state->have = 0; /* no output data available */
79 state->eof = 0; /* not at end of file */ 78 state->eof = 0; /* not at end of file */
79 state->how = LOOK; /* look for gzip header */
80 state->direct = 1; /* default for empty file */
80 } 81 }
81 state->seek = 0; /* no seek request pending */ 82 state->seek = 0; /* no seek request pending */
82 gz_error(state, Z_OK, NULL); /* clear error */ 83 gz_error(state, Z_OK, NULL); /* clear error */
@@ -85,11 +86,10 @@ local void gz_reset(state)
85} 86}
86 87
87/* Open a gzip file either by name or file descriptor. */ 88/* Open a gzip file either by name or file descriptor. */
88local gzFile gz_open(path, fd, mode, large) 89local gzFile gz_open(path, fd, mode)
89 const char *path; 90 const char *path;
90 int fd; 91 int fd;
91 const char *mode; 92 const char *mode;
92 int large;
93{ 93{
94 gz_statep state; 94 gz_statep state;
95 95
@@ -152,13 +152,9 @@ local gzFile gz_open(path, fd, mode, large)
152 /* open the file with the appropriate mode (or just use fd) */ 152 /* open the file with the appropriate mode (or just use fd) */
153 state->fd = fd != -1 ? fd : 153 state->fd = fd != -1 ? fd :
154 open(path, 154 open(path,
155 (large ?
156#ifdef O_LARGEFILE 155#ifdef O_LARGEFILE
157 O_LARGEFILE 156 O_LARGEFILE |
158#else
159 0
160#endif 157#endif
161 : 0) |
162#ifdef O_BINARY 158#ifdef O_BINARY
163 O_BINARY | 159 O_BINARY |
164#endif 160#endif
@@ -178,6 +174,10 @@ local gzFile gz_open(path, fd, mode, large)
178 174
179 /* save the path name for error messages */ 175 /* save the path name for error messages */
180 state->path = malloc(strlen(path) + 1); 176 state->path = malloc(strlen(path) + 1);
177 if (state->path == NULL) {
178 free(state);
179 return NULL;
180 }
181 strcpy(state->path, path); 181 strcpy(state->path, path);
182 182
183 /* save the current position for rewinding (only if reading) */ 183 /* save the current position for rewinding (only if reading) */
@@ -198,7 +198,7 @@ gzFile ZEXPORT gzopen(path, mode)
198 const char *path; 198 const char *path;
199 const char *mode; 199 const char *mode;
200{ 200{
201 return gz_open(path, -1, mode, 0); 201 return gz_open(path, -1, mode);
202} 202}
203 203
204/* -- see zlib.h -- */ 204/* -- see zlib.h -- */
@@ -206,7 +206,7 @@ gzFile ZEXPORT gzopen64(path, mode)
206 const char *path; 206 const char *path;
207 const char *mode; 207 const char *mode;
208{ 208{
209 return gz_open(path, -1, mode, 1); 209 return gz_open(path, -1, mode);
210} 210}
211 211
212/* -- see zlib.h -- */ 212/* -- see zlib.h -- */
@@ -216,14 +216,14 @@ gzFile ZEXPORT gzdopen(fd, mode)
216{ 216{
217 char path[46]; /* identifier for error messages */ 217 char path[46]; /* identifier for error messages */
218 218
219 if (fd < 0) 219 if (fd == -1)
220 return NULL; 220 return NULL;
221#ifdef NO_snprintf 221#ifdef NO_snprintf
222 sprintf(path, "<fd:%d>", fd); /* big enough for 128-bit integers */ 222 sprintf(path, "<fd:%d>", fd); /* big enough for 128-bit integers */
223#else 223#else
224 snprintf(path, sizeof(path), "<fd:%d>", fd); 224 snprintf(path, sizeof(path), "<fd:%d>", fd);
225#endif 225#endif
226 return gz_open(path, fd, mode, 0); 226 return gz_open(path, fd, mode);
227} 227}
228 228
229/* -- see zlib.h -- */ 229/* -- see zlib.h -- */
@@ -303,7 +303,7 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
303 offset -= state->pos; 303 offset -= state->pos;
304 304
305 /* if within raw area while reading, just go there */ 305 /* if within raw area while reading, just go there */
306 if (state->mode == GZ_READ && state->how == 1 && 306 if (state->mode == GZ_READ && state->how == COPY &&
307 state->pos + offset >= state->raw) { 307 state->pos + offset >= state->raw) {
308 ret = LSEEK(state->fd, offset, SEEK_CUR); 308 ret = LSEEK(state->fd, offset, SEEK_CUR);
309 if (ret == -1) 309 if (ret == -1)