8 #if defined(_WIN32) && !defined(__BORLANDC__)
9 # define LSEEK _lseeki64
11 #if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
12 # define LSEEK lseek64
30 static char buf[1024];
33 DWORD lasterr = GetLastError();
34 DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
35 | FORMAT_MESSAGE_ALLOCATE_BUFFER,
45 && msgbuf[chars - 2] ==
'\r' && msgbuf[chars - 1] ==
'\n') {
50 if (chars >
sizeof (buf) - 1) {
51 chars =
sizeof (
buf) - 1;
55 wcstombs(buf, msgbuf, chars + 1);
59 sprintf(buf,
"unknown win32 error (%ld)", error);
62 SetLastError(lasterr);
81 state->strm.avail_in = 0;
114 if (*mode >=
'0' && *mode <=
'9')
115 state->level = *mode -
'0';
121 #ifndef NO_GZCOMPRESS
151 state->strategy =
Z_RLE;
183 len = wcstombs(NULL, path, 0);
189 len = strlen((
const char *)path);
190 state->path = (
char *)
malloc(len + 1);
191 if (state->path == NULL) {
198 wcstombs(state->path, path, len + 1);
203 #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
204 (void)snprintf(state->path, len + 1,
"%s", (
const char *)path);
206 strcpy(state->path, path);
218 (cloexec ? O_CLOEXEC : 0) |
222 (O_WRONLY | O_CREAT |
224 (exclusive ? O_EXCL : 0) |
231 state->fd = fd > -1 ? fd : (
233 fd == -2 ? _wopen(path, oflag, 0666) :
235 open((
const char *)path, oflag, 0666));
236 if (state->fd == -1) {
249 if (state->start == -1) state->start = 0;
261 return gz_open(path, -1, mode);
266 return gz_open(path, -1, mode);
274 if (fd == -1 || (path = (
char *)
malloc(7 + 3 *
sizeof(
int))) == NULL)
276 #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
277 (void)snprintf(path, 7 + 3 *
sizeof(
int),
"<fd:%d>", fd);
279 sprintf(path,
"<fd:%d>", fd);
289 return gz_open(path, -2, mode);
305 if (state->size != 0)
309 if ((size << 1) <
size)
361 offset -= state->x.
pos;
362 else if (state->seek)
363 offset += state->skip;
367 if (state->mode ==
GZ_READ && state->how ==
COPY &&
368 state->x.pos + offset >= 0) {
377 state->strm.avail_in = 0;
386 offset += state->x.pos;
396 (
unsigned)offset : state->x.have;
408 return state->x.pos +
offset;
431 return state->x.
pos + (state->seek ? state->skip : 0);
459 offset -= state->strm.avail_in;
483 return state->mode ==
GZ_READ ? state->past : 0;
499 *errnum = state->err;
500 return state->err ==
Z_MEM_ERROR ?
"out of memory" :
501 (state->msg == NULL ?
"" : state->msg);
531 if (state->msg != NULL) {
551 if ((state->msg = (
char *)
malloc(strlen(state->path) + strlen(msg) + 3)) ==
556 #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
557 (void)snprintf(state->msg, strlen(state->path) + strlen(msg) + 3,
558 "%s%s%s", state->path,
": ", msg);
560 strcpy(state->msg, state->path);
561 strcat(state->msg,
": ");
562 strcat(state->msg, msg);
int ZEXPORT gzeof(gzFile file)
z_off64_t ZEXPORT gzoffset64(gzFile file)
z_off_t ZEXPORT gztell(gzFile file)
unsigned ZLIB_INTERNAL gz_intmax(void)
int ZEXPORT gzrewind(gzFile file)
z_off64_t ZEXPORT gztell64(gzFile file)
z_off_t ZEXPORT gzseek(gzFile file, z_off_t offset, int whence)
void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg)
local gzFile gz_open(const void *path, int fd, const char *mode)
int ZEXPORT gzbuffer(gzFile file, unsigned size)
gzFile ZEXPORT gzdopen(int fd, const char *mode)
z_off_t ZEXPORT gzoffset(gzFile file)
gzFile ZEXPORT gzopen(const char *path, const char *mode)
const char *ZEXPORT gzerror(gzFile file, int *errnum)
local void gz_reset(gz_statep state)
void ZEXPORT gzclearerr(gzFile file)
#define Z_DEFAULT_STRATEGY
gzFile ZEXPORT gzopen64(const char *path, const char *mode)
z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence)
#define Z_DEFAULT_COMPRESSION