8 #if defined(_WIN32) && !defined(__BORLANDC__)
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;
191 len = wcstombs(NULL, path, 0);
192 if (len == (
size_t)-1)
198 state->path = malloc(len + 1);
199 if (state->path == NULL) {
206 wcstombs(state->path, path, len + 1);
211 strcpy(state->path, path);
222 (cloexec ? O_CLOEXEC : 0) |
226 (O_WRONLY | O_CREAT |
228 (exclusive ? O_EXCL : 0) |
235 state->fd = fd > -1 ? fd : (
237 fd == -2 ? _wopen(path, oflag, 0666) :
239 open(path, oflag, 0666));
240 if (state->fd == -1) {
251 if (state->start == -1) state->start = 0;
266 return gz_open(path, -1, mode);
274 return gz_open(path, -1, mode);
285 if (fd == -1 || (path = malloc(7 + 3 *
sizeof(
int))) == NULL)
287 sprintf(path,
"<fd:%d>", fd);
299 return gz_open(path, -2, mode);
318 if (state->size != 0)
378 offset -= state->x.pos;
379 else if (state->seek)
380 offset += state->skip;
384 if (state->mode ==
GZ_READ && state->how ==
COPY &&
385 state->x.pos + offset >= 0) {
394 state->strm.avail_in = 0;
395 state->x.pos += offset;
403 offset += state->x.pos;
413 (
unsigned)offset : state->x.have;
423 state->skip = offset;
425 return state->x.pos + offset;
454 return state->x.pos + (state->seek ? state->skip : 0);
486 offset -= state->strm.avail_in;
514 return state->mode ==
GZ_READ ? state->past : 0;
533 *errnum = state->err;
534 return state->msg == NULL ?
"" : state->msg;
570 if (state->msg != NULL) {
587 state->msg = (
char *)msg;
592 if ((state->msg = malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) {
594 state->msg = (
char *)
"out of memory";
597 strcpy(state->msg, state->path);
598 strcat(state->msg,
": ");
599 strcat(state->msg, msg);