diff options
Diffstat (limited to 'gzlib.c')
-rw-r--r-- | gzlib.c | 69 |
1 files changed, 36 insertions, 33 deletions
@@ -18,21 +18,17 @@ local void gz_reset OF((gz_statep)); | |||
18 | local gzFile gz_open OF((const char *, int, const char *, int)); | 18 | local gzFile gz_open OF((const char *, int, const char *, int)); |
19 | 19 | ||
20 | #if defined UNDER_CE && defined NO_ERRNO_H | 20 | #if defined UNDER_CE && defined NO_ERRNO_H |
21 | local char *strwinerror OF((DWORD error)); | ||
22 | 21 | ||
23 | # include <windows.h> | 22 | /* Map the Windows error number in ERROR to a locale-dependent error message |
23 | string and return a pointer to it. Typically, the values for ERROR come | ||
24 | from GetLastError. | ||
24 | 25 | ||
25 | /* Map the Windows error number in ERROR to a locale-dependent error | 26 | The string pointed to shall not be modified by the application, but may be |
26 | message string and return a pointer to it. Typically, the values | 27 | overwritten by a subsequent call to gz_strwinerror |
27 | for ERROR come from GetLastError. | ||
28 | 28 | ||
29 | The string pointed to shall not be modified by the application, | 29 | The gz_strwinerror function does not change the current setting of |
30 | but may be overwritten by a subsequent call to strwinerror | 30 | GetLastError. */ |
31 | 31 | char ZEXPORT *gz_strwinerror (error) | |
32 | The strwinerror function does not change the current setting | ||
33 | of GetLastError. */ | ||
34 | |||
35 | local char *strwinerror (error) | ||
36 | DWORD error; | 32 | DWORD error; |
37 | { | 33 | { |
38 | static char buf[1024]; | 34 | static char buf[1024]; |
@@ -82,18 +78,18 @@ local void gz_reset(state) | |||
82 | state->have = 0; /* no output data available */ | 78 | state->have = 0; /* no output data available */ |
83 | state->eof = 0; /* not at end of file */ | 79 | state->eof = 0; /* not at end of file */ |
84 | } | 80 | } |
85 | state->seek = 0; /* no seek request pending */ | 81 | state->seek = 0; /* no seek request pending */ |
86 | gz_error(state, Z_OK, NULL); /* clear error */ | 82 | gz_error(state, Z_OK, NULL); /* clear error */ |
87 | state->pos = 0; /* no uncompressed data yet */ | 83 | state->pos = 0; /* no uncompressed data yet */ |
88 | state->strm.avail_in = 0; /* no input data yet */ | 84 | state->strm.avail_in = 0; /* no input data yet */ |
89 | } | 85 | } |
90 | 86 | ||
91 | /* Open a gzip file either by name or file descriptor. */ | 87 | /* Open a gzip file either by name or file descriptor. */ |
92 | local gzFile gz_open(path, fd, mode, use64) | 88 | local gzFile gz_open(path, fd, mode, large) |
93 | const char *path; | 89 | const char *path; |
94 | int fd; | 90 | int fd; |
95 | const char *mode; | 91 | const char *mode; |
96 | int use64; | 92 | int large; |
97 | { | 93 | { |
98 | gz_statep state; | 94 | gz_statep state; |
99 | 95 | ||
@@ -156,9 +152,13 @@ local gzFile gz_open(path, fd, mode, use64) | |||
156 | /* open the file with the appropriate mode (or just use fd) */ | 152 | /* open the file with the appropriate mode (or just use fd) */ |
157 | state->fd = fd != -1 ? fd : | 153 | state->fd = fd != -1 ? fd : |
158 | open(path, | 154 | open(path, |
155 | (large ? | ||
159 | #ifdef O_LARGEFILE | 156 | #ifdef O_LARGEFILE |
160 | (use64 ? O_LARGEFILE : 0) | | 157 | O_LARGEFILE |
158 | #else | ||
159 | 0 | ||
161 | #endif | 160 | #endif |
161 | : 0) | | ||
162 | #ifdef O_BINARY | 162 | #ifdef O_BINARY |
163 | O_BINARY | | 163 | O_BINARY | |
164 | #endif | 164 | #endif |
@@ -214,13 +214,16 @@ gzFile ZEXPORT gzdopen(fd, mode) | |||
214 | int fd; | 214 | int fd; |
215 | const char *mode; | 215 | const char *mode; |
216 | { | 216 | { |
217 | char path[46]; /* allow up to 128-bit integers, so don't worry -- | 217 | char path[46]; /* identifier for error messages */ |
218 | the sprintf() is safe */ | ||
219 | 218 | ||
220 | if (fd < 0) | 219 | if (fd < 0) |
221 | return NULL; | 220 | return NULL; |
222 | sprintf(path, "<fd:%d>", fd); /* for error messages */ | 221 | #ifdef NO_snprintf |
223 | return gz_open(path, fd, mode, 1); | 222 | sprintf(path, "<fd:%d>", fd); /* big enough for 128-bit integers */ |
223 | #else | ||
224 | snprintf(path, sizeof(path), "<fd:%d>", fd); | ||
225 | #endif | ||
226 | return gz_open(path, fd, mode, 0); | ||
224 | } | 227 | } |
225 | 228 | ||
226 | /* -- see zlib.h -- */ | 229 | /* -- see zlib.h -- */ |
@@ -325,7 +328,7 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence) | |||
325 | return -1; | 328 | return -1; |
326 | } | 329 | } |
327 | 330 | ||
328 | /* if reading, skip what's in output buffer (one less gz_getc() check) */ | 331 | /* if reading, skip what's in output buffer (one less gzgetc() check) */ |
329 | if (state->mode == GZ_READ) { | 332 | if (state->mode == GZ_READ) { |
330 | n = state->have > offset ? (unsigned)offset : state->have; | 333 | n = state->have > offset ? (unsigned)offset : state->have; |
331 | state->have -= n; | 334 | state->have -= n; |
@@ -422,10 +425,10 @@ int ZEXPORT gzeof(file) | |||
422 | 425 | ||
423 | /* get internal structure and check integrity */ | 426 | /* get internal structure and check integrity */ |
424 | if (file == NULL) | 427 | if (file == NULL) |
425 | return -1; | 428 | return 0; |
426 | state = (gz_statep)file; | 429 | state = (gz_statep)file; |
427 | if (state->mode != GZ_READ && state->mode != GZ_WRITE) | 430 | if (state->mode != GZ_READ && state->mode != GZ_WRITE) |
428 | return -1; | 431 | return 0; |
429 | 432 | ||
430 | /* return end-of-file state */ | 433 | /* return end-of-file state */ |
431 | return state->mode == GZ_READ ? (state->eof && state->have == 0) : 0; | 434 | return state->mode == GZ_READ ? (state->eof && state->have == 0) : 0; |
@@ -470,15 +473,15 @@ void ZEXPORT gzclearerr(file) | |||
470 | } | 473 | } |
471 | 474 | ||
472 | /* Create an error message in allocated memory and set state->err and | 475 | /* Create an error message in allocated memory and set state->err and |
473 | state->msg accordingly. Free any previous error message already there. Do | 476 | state->msg accordingly. Free any previous error message already there. Do |
474 | not try to free or allocate space if the error is Z_MEM_ERROR (out of | 477 | not try to free or allocate space if the error is Z_MEM_ERROR (out of |
475 | memory). Simply save the error message as a static string. If there is | 478 | memory). Simply save the error message as a static string. If there is an |
476 | an allocation failure constructing the error message, then convert the | 479 | allocation failure constructing the error message, then convert the error to |
477 | error to out of memory. */ | 480 | out of memory. */ |
478 | void ZEXPORT gz_error(state, err, msg) | 481 | void ZEXPORT gz_error(state, err, msg) |
479 | gz_statep state; | 482 | gz_statep state; |
480 | int err; | 483 | int err; |
481 | char *msg; | 484 | const char *msg; |
482 | { | 485 | { |
483 | /* free previously allocated message and clear */ | 486 | /* free previously allocated message and clear */ |
484 | if (state->msg != NULL) { | 487 | if (state->msg != NULL) { |
@@ -494,14 +497,14 @@ void ZEXPORT gz_error(state, err, msg) | |||
494 | 497 | ||
495 | /* for an out of memory error, save as static string */ | 498 | /* for an out of memory error, save as static string */ |
496 | if (err == Z_MEM_ERROR) { | 499 | if (err == Z_MEM_ERROR) { |
497 | state->msg = msg; | 500 | state->msg = (char *)msg; |
498 | return; | 501 | return; |
499 | } | 502 | } |
500 | 503 | ||
501 | /* construct error message with path */ | 504 | /* construct error message with path */ |
502 | if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) { | 505 | if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) { |
503 | state->err = Z_MEM_ERROR; | 506 | state->err = Z_MEM_ERROR; |
504 | state->msg = "out of memory"; | 507 | state->msg = (char *)"out of memory"; |
505 | return; | 508 | return; |
506 | } | 509 | } |
507 | strcpy(state->msg, state->path); | 510 | strcpy(state->msg, state->path); |