8 #if defined(_WIN32) && !defined(__BORLANDC__) && !defined(__MINGW32__)
9 # define LSEEK _lseeki64
11 #if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
12 # define LSEEK lseek64
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);
87 state->strm.avail_in = 0;
124 if (*mode >=
'0' && *mode <=
'9')
125 state->level = *mode -
'0';
131 #ifndef NO_GZCOMPRESS
161 state->strategy =
Z_RLE;
193 len = wcstombs(NULL, path, 0);
194 if (len == (z_size_t)-1)
199 len = strlen((
const char *)path);
200 state->path = (
char *)malloc(len + 1);
201 if (state->path == NULL) {
208 wcstombs(state->path, path, len + 1);
213 #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
214 (
void)snprintf(state->path, len + 1,
"%s", (
const char *)path);
216 strcpy(state->path, path);
228 (cloexec ? O_CLOEXEC : 0) |
232 (O_WRONLY | O_CREAT |
234 (exclusive ? O_EXCL : 0) |
241 state->fd = fd > -1 ? fd : (
243 fd == -2 ? _wopen(path, oflag, 0666) :
245 open((
const char *)path, oflag, 0666));
246 if (state->fd == -1) {
252 LSEEK(state->fd, 0, SEEK_END);
258 state->start =
LSEEK(state->fd, 0, SEEK_CUR);
259 if (state->start == -1) state->start = 0;
274 return gz_open(path, -1, mode);
282 return gz_open(path, -1, mode);
293 if (fd == -1 || (path = (
char *)malloc(7 + 3 *
sizeof(
int))) == NULL)
295 #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
296 (
void)snprintf(path, 7 + 3 *
sizeof(
int),
"<fd:%d>",
fd);
298 sprintf(path,
"<fd:%d>", fd);
307 gzFile ZEXPORT gzopen_w(path, mode)
311 return gz_open(path, -2, mode);
330 if (state->size != 0)
334 if ((size << 1) < size)
359 if (
LSEEK(state->fd, state->start, SEEK_SET) == -1)
387 if (whence != SEEK_SET && whence != SEEK_CUR)
391 if (whence == SEEK_SET)
392 offset -= state->x.pos;
393 else if (state->seek)
394 offset += state->skip;
398 if (state->mode ==
GZ_READ && state->how ==
COPY &&
399 state->x.pos + offset >= 0) {
400 ret =
LSEEK(state->fd, offset - state->x.have, SEEK_CUR);
408 state->strm.avail_in = 0;
417 offset += state->x.pos;
426 n =
GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ?
427 (
unsigned)offset : state->x.have;
439 return state->x.pos +
offset;
450 ret =
gzseek64(file, (z_off64_t)offset, whence);
451 return ret == (z_off_t)ret ? (z_off_t)ret : -1;
468 return state->x.pos + (state->seek ? state->skip : 0);
478 return ret == (z_off_t)ret ? (z_off_t)ret : -1;
496 offset =
LSEEK(state->fd, 0, SEEK_CUR);
500 offset -= state->strm.avail_in;
511 return ret == (z_off_t)ret ? (z_off_t)ret : -1;
528 return state->mode ==
GZ_READ ? state->past : 0;
547 *errnum = state->err;
548 return state->err ==
Z_MEM_ERROR ?
"out of memory" :
549 (state->msg == NULL ?
"" : state->msg);
585 if (state->msg != NULL) {
605 if ((state->msg = (
char *)malloc(strlen(state->path) + strlen(msg) + 3)) ==
610 #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
611 (
void)snprintf(state->msg, strlen(state->path) + strlen(msg) + 3,
612 "%s%s%s", state->path,
": ", msg);
614 strcpy(state->msg, state->path);
615 strcat(state->msg,
": ");
616 strcat(state->msg, msg);