8#if defined(_WIN32) && !defined(__BORLANDC__)
9# define LSEEK _lseeki64
11#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
36 static char buf[1024];
39 DWORD lasterr = GetLastError();
40 DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
41 | FORMAT_MESSAGE_ALLOCATE_BUFFER,
51 && msgbuf[chars - 2] ==
'\r' && msgbuf[chars - 1] ==
'\n') {
56 if (chars >
sizeof (buf) - 1) {
57 chars =
sizeof (buf) - 1;
61 wcstombs(buf, msgbuf, chars + 1);
65 sprintf(buf,
"unknown win32 error (%ld)", error);
68 SetLastError(lasterr);
89 state->strm.avail_in = 0;
126 if (*mode >=
'0' && *mode <=
'9')
127 state->level = *mode -
'0';
163 state->strategy =
Z_RLE;
195 len = wcstombs(NULL, path, 0);
196 if (len == (z_size_t)-1)
201 len = strlen((
const char *)path);
202 state->path = (
char *)malloc(len + 1);
203 if (state->path == NULL) {
210 wcstombs(state->path, path, len + 1);
215#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
216 (void)snprintf(state->path, len + 1,
"%s", (
const char *)path);
218 strcpy(state->path, path);
230 (cloexec ? O_CLOEXEC : 0) |
234 (O_WRONLY | O_CREAT |
236 (exclusive ? O_EXCL : 0) |
243 state->fd = fd > -1 ? fd : (
245 fd == -2 ? _wopen(path, oflag, 0666) :
247 open((
const char *)path, oflag, 0666));
248 if (state->fd == -1) {
254 LSEEK(state->fd, 0, SEEK_END);
260 state->start =
LSEEK(state->fd, 0, SEEK_CUR);
261 if (state->start == -1) state->start = 0;
276 return gz_open(path, -1, mode);
284 return gz_open(path, -1, mode);
295 if (fd == -1 || (path = (
char *)malloc(7 + 3 *
sizeof(
int))) == NULL)
297#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
298 (void)snprintf(path, 7 + 3 *
sizeof(
int),
"<fd:%d>", fd);
300 sprintf(path,
"<fd:%d>", fd);
309gzFile ZEXPORT gzopen_w(path, mode)
313 return gz_open(path, -2, mode);
332 if (state->size != 0)
336 if ((size << 1) < size)
361 if (
LSEEK(state->fd, state->start, SEEK_SET) == -1)
389 if (whence != SEEK_SET && whence != SEEK_CUR)
393 if (whence == SEEK_SET)
394 offset -= state->x.pos;
395 else if (state->seek)
396 offset += state->skip;
400 if (state->mode ==
GZ_READ && state->how ==
COPY &&
401 state->x.pos + offset >= 0) {
402 ret =
LSEEK(state->fd, offset - (z_off64_t)state->x.have, SEEK_CUR);
410 state->strm.avail_in = 0;
411 state->x.pos += offset;
419 offset += state->x.pos;
428 n =
GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ?
429 (
unsigned)offset : state->x.have;
439 state->skip = offset;
441 return state->x.pos + offset;
445z_off_t ZEXPORT
gzseek(file, offset, whence)
452 ret =
gzseek64(file, (z_off64_t)offset, whence);
453 return ret == (z_off_t)ret ? (z_off_t)ret : -1;
470 return state->x.pos + (state->seek ? state->skip : 0);
480 return ret == (z_off_t)ret ? (z_off_t)ret : -1;
498 offset =
LSEEK(state->fd, 0, SEEK_CUR);
502 offset -= state->strm.avail_in;
513 return ret == (z_off_t)ret ? (z_off_t)ret : -1;
530 return state->mode ==
GZ_READ ? state->past : 0;
549 *errnum = state->err;
550 return state->err ==
Z_MEM_ERROR ?
"out of memory" :
551 (state->msg == NULL ?
"" : state->msg);
587 if (state->msg != NULL) {
607 if ((state->msg = (
char *)malloc(strlen(state->path) + strlen(msg) + 3)) ==
612#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
613 (void)snprintf(state->msg, strlen(state->path) + strlen(msg) + 3,
614 "%s%s%s", state->path,
": ", msg);
616 strcpy(state->msg, state->path);
617 strcat(state->msg,
": ");
618 strcat(state->msg, msg);
void ZEXPORT gzclearerr(gzFile file)
z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence)
int ZEXPORT gzrewind(gzFile file)
z_off64_t ZEXPORT gztell64(gzFile file)
unsigned ZLIB_INTERNAL gz_intmax()
gzFile ZEXPORT gzopen64(char *path, const char *mode) const
z_off_t ZEXPORT gzseek(gzFile file, z_off_t offset, int whence)
gzFile ZEXPORT gzopen(char *path, const char *mode) const
int ZEXPORT gzeof(gzFile file)
gzFile ZEXPORT gzdopen(int fd, const char *mode)
z_off64_t ZEXPORT gzoffset64(gzFile file)
const char *ZEXPORT gzerror(gzFile file, int *errnum)
z_off_t ZEXPORT gzoffset(gzFile file)
void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg)
z_off_t ZEXPORT gztell(gzFile file)
int ZEXPORT gzbuffer(gzFile file, unsigned size)
local void gz_reset(gz_statep state)
local gzFile gz_open(void *path, int fd, const char *mode) const
voidpf alloc_func OF((voidpf opaque, uInt items, uInt size))
#define Z_DEFAULT_STRATEGY
#define Z_DEFAULT_COMPRESSION