8 #if defined(_WIN32) && !defined(__BORLANDC__)
9 # define LSEEK _lseeki64
11 #if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
12 # define LSEEK lseek64
35 static char buf[1024];
38 DWORD lasterr = GetLastError();
39 DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
40 | FORMAT_MESSAGE_ALLOCATE_BUFFER,
50 && msgbuf[chars - 2] ==
'\r' && msgbuf[chars - 1] ==
'\n') {
55 if (chars >
sizeof (buf) - 1) {
56 chars =
sizeof (buf) - 1;
60 wcstombs(buf, msgbuf, chars + 1);
64 sprintf(buf,
"unknown win32 error (%ld)", error);
67 SetLastError(lasterr);
85 state->strm.avail_in = 0;
119 if (*mode >=
'0' && *mode <=
'9')
120 state->level = *mode -
'0';
126 #ifndef NO_GZCOMPRESS
156 state->strategy =
Z_RLE;
188 len = wcstombs(NULL, (
const wchar_t *)path, 0);
189 if (len == (
size_t)-1)
194 len = strlen((
const char *)path);
195 state->path = (
char*)malloc(len + 1);
196 if (state->path == NULL) {
203 wcstombs(state->path, (
const wchar_t *)path, len + 1);
208 #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
209 snprintf(state->path, len + 1,
"%s", (
const char *)path);
211 strcpy(state->path, path);
223 (cloexec ? O_CLOEXEC : 0) |
227 (O_WRONLY | O_CREAT |
229 (exclusive ? O_EXCL : 0) |
236 state->fd = fd > -1 ? fd : (
238 fd == -2 ? _wopen((
const wchar_t *)path, oflag, 0666) :
240 open((
const char *)path, oflag, 0666));
241 if (state->fd == -1) {
251 state->start =
LSEEK(state->fd, 0, SEEK_CUR);
252 if (state->start == -1) state->start = 0;
265 return gz_open(path, -1, mode);
271 return gz_open(path, -1, mode);
280 if (fd == -1 || (path = (
char *)malloc(7 + 3 *
sizeof(
int))) == NULL)
282 #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
283 snprintf(path, 7 + 3 *
sizeof(
int),
"<fd:%d>", fd);
285 sprintf(path,
"<fd:%d>", fd);
294 gzFile ZEXPORT gzopen_w(
const wchar_t *path,
const char *mode)
296 return gz_open(path, -2, mode);
313 if (state->size != 0)
339 if (
LSEEK(state->fd, state->start, SEEK_SET) == -1)
364 if (whence != SEEK_SET && whence != SEEK_CUR)
368 if (whence == SEEK_SET)
369 offset -= state->x.
pos;
370 else if (state->seek)
371 offset += state->skip;
375 if (state->mode ==
GZ_READ && state->how ==
COPY &&
376 state->x.pos + offset >= 0) {
377 ret =
LSEEK(state->fd, offset - state->x.have, SEEK_CUR);
385 state->strm.avail_in = 0;
386 state->x.pos += offset;
394 offset += state->x.pos;
403 n =
GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ?
404 (
unsigned)offset : state->x.have;
414 state->skip = offset;
416 return state->x.pos + offset;
424 ret =
gzseek64(file, (z_off64_t)offset, whence);
425 return ret == (z_off_t)ret ? (z_off_t)ret : -1;
441 return state->x.
pos + (state->seek ? state->skip : 0);
450 return ret == (z_off_t)ret ? (z_off_t)ret : -1;
467 offset =
LSEEK(state->fd, 0, SEEK_CUR);
471 offset -= state->strm.avail_in;
481 return ret == (z_off_t)ret ? (z_off_t)ret : -1;
497 return state->mode ==
GZ_READ ? state->past : 0;
514 *errnum = state->err;
515 return state->err ==
Z_MEM_ERROR ?
"out of memory" :
516 (state->msg == NULL ?
"" : state->msg);
548 if (state->msg != NULL) {
568 if ((state->msg = (
char *)malloc(strlen(state->path) + strlen(msg) + 3)) ==
573 #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
574 snprintf(state->msg, strlen(state->path) + strlen(msg) + 3,
575 "%s%s%s", state->path,
": ", msg);
577 strcpy(state->msg, state->path);
578 strcat(state->msg,
": ");
579 strcat(state->msg, msg);
void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg)
z_off_t ZEXPORT gzoffset(gzFile file)
z_off_t ZEXPORT gzseek(gzFile file, z_off_t offset, int whence)
void ZEXPORT gzclearerr(gzFile file)
z_off64_t ZEXPORT gzoffset64(gzFile file)
const char *ZEXPORT gzerror(gzFile file, int *errnum)
z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence)
local gzFile gz_open(const void *path, int fd, const char *mode)
int ZEXPORT gzeof(gzFile file)
gzFile ZEXPORT gzopen64(const char *path, const char *mode)
z_off_t ZEXPORT gztell(gzFile file)
unsigned ZLIB_INTERNAL gz_intmax()
local void gz_reset(gz_statep state)
z_off64_t ZEXPORT gztell64(gzFile file)
gzFile ZEXPORT gzopen(const char *path, const char *mode)
int ZEXPORT gzrewind(gzFile file)
int ZEXPORT gzbuffer(gzFile file, unsigned size)
gzFile ZEXPORT gzdopen(int fd, const char *mode)
static PROLOG_HANDLER error
#define Z_DEFAULT_STRATEGY
#define Z_DEFAULT_COMPRESSION
voidpf alloc_func OF((voidpf opaque, uInt items, uInt size))