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;
186 len = wcstombs(NULL, (
const wchar_t *)path, 0);
187 if (len == (
size_t)-1)
192 len = strlen((
const char *)path);
193 state->path = (
char*)
malloc(len + 1);
194 if (state->path == NULL) {
201 wcstombs(state->path, (
const wchar_t *)path, len + 1);
206 strcpy(state->path, (
const char *)path);
217 (cloexec ? O_CLOEXEC : 0) |
221 (O_WRONLY | O_CREAT |
223 (exclusive ? O_EXCL : 0) |
230 state->fd = fd > -1 ? fd : (
232 fd == -2 ? _wopen((
const wchar_t *)path, oflag, 0666) :
234 open((
const char *)path, oflag, 0666));
235 if (state->fd == -1) {
245 state->start =
LSEEK(state->fd, 0, SEEK_CUR);
246 if (state->start == -1) state->start = 0;
259 return gz_open(path, -1, mode);
265 return gz_open(path, -1, mode);
274 if (fd == -1 || (path = (
char *)
malloc(7 + 3 *
sizeof(
int))) == NULL)
276 sprintf(path,
"<fd:%d>", fd);
284 gzFile ZEXPORT gzopen_w(
const wchar_t *path,
const char *mode)
286 return gz_open(path, -2, mode);
303 if (state->size != 0)
329 if (
LSEEK(state->fd, state->start, SEEK_SET) == -1)
354 if (whence != SEEK_SET && whence != SEEK_CUR)
358 if (whence == SEEK_SET)
359 offset -= state->x.
pos;
360 else if (state->seek)
361 offset += state->skip;
365 if (state->mode ==
GZ_READ && state->how ==
COPY &&
366 state->x.pos + offset >= 0) {
367 ret =
LSEEK(state->fd, offset - state->x.have, SEEK_CUR);
375 state->strm.avail_in = 0;
376 state->x.pos += offset;
384 offset += state->x.pos;
393 n =
GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ?
394 (
unsigned)offset : state->x.have;
404 state->skip = offset;
406 return state->x.pos + offset;
414 ret =
gzseek64(file, (z_off64_t)offset, whence);
415 return ret == (z_off_t)ret ? (z_off_t)ret : -1;
431 return state->x.
pos + (state->seek ? state->skip : 0);
440 return ret == (z_off_t)ret ? (z_off_t)ret : -1;
457 offset =
LSEEK(state->fd, 0, SEEK_CUR);
461 offset -= state->strm.avail_in;
471 return ret == (z_off_t)ret ? (z_off_t)ret : -1;
487 return state->mode ==
GZ_READ ? state->past : 0;
504 *errnum = state->err;
505 return state->msg == NULL ?
"" : state->msg;
537 if (state->msg != NULL) {
554 state->msg = (
char *)msg;
559 if ((state->msg = (
char *)
malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) {
561 state->msg = (
char *)
"out of memory";
564 strcpy(state->msg, state->path);
565 strcat(state->msg,
": ");
566 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)
#define Z_DEFAULT_STRATEGY
void * malloc(size_t __size)
#define Z_DEFAULT_COMPRESSION
voidpf alloc_func OF((voidpf opaque, uInt items, uInt size))