Deleted Added
full compact
2c2
< * Copyright (C) 2004, 2010 Mark Adler
---
> * Copyright (C) 2004, 2010, 2011, 2012 Mark Adler
6c6
< /* $FreeBSD: head/lib/libz/gzlib.c 206924 2010-04-20 21:14:30Z delphij $ */
---
> /* $FreeBSD: head/lib/libz/gzlib.c 237410 2012-06-21 21:47:08Z delphij $ */
10a11,13
> #if defined(_WIN32) && !defined(__BORLANDC__)
> # define LSEEK _lseeki64
> #else
15a19
> #endif
19c23
< local gzFile gz_open OF((const char *, int, const char *));
---
> local gzFile gz_open OF((const void *, int, const char *));
76a81
> state->x.have = 0; /* no output data available */
78d82
< state->have = 0; /* no output data available */
79a84
> state->past = 0; /* have not read past end yet */
81d85
< state->direct = 1; /* default for empty file */
85c89
< state->pos = 0; /* no uncompressed data yet */
---
> state->x.pos = 0; /* no uncompressed data yet */
91c95
< const char *path;
---
> const void *path;
95a100,107
> size_t len;
> int oflag;
> #ifdef O_CLOEXEC
> int cloexec = 0;
> #endif
> #ifdef O_EXCL
> int exclusive = 0;
> #endif
96a109,112
> /* check input */
> if (path == NULL)
> return NULL;
>
108a125
> state->direct = 0;
129a147,156
> #ifdef O_CLOEXEC
> case 'e':
> cloexec = 1;
> break;
> #endif
> #ifdef O_EXCL
> case 'x':
> exclusive = 1;
> break;
> #endif
140a168,169
> case 'T':
> state->direct = 1;
152a182,190
> /* can't force transparent read */
> if (state->mode == GZ_READ) {
> if (state->direct) {
> free(state);
> return NULL;
> }
> state->direct = 1; /* for empty file */
> }
>
154c192,201
< state->path = malloc(strlen(path) + 1);
---
> #ifdef _WIN32
> if (fd == -2) {
> len = wcstombs(NULL, path, 0);
> if (len == (size_t)-1)
> len = 0;
> }
> else
> #endif
> len = strlen(path);
> state->path = malloc(len + 1);
159c206,214
< strcpy(state->path, path);
---
> #ifdef _WIN32
> if (fd == -2)
> if (len)
> wcstombs(state->path, path, len + 1);
> else
> *(state->path) = 0;
> else
> #endif
> strcpy(state->path, path);
161,163c216,217
< /* open the file with the appropriate mode (or just use fd) */
< state->fd = fd != -1 ? fd :
< open(path,
---
> /* compute the flags for open() */
> oflag =
165c219
< O_LARGEFILE |
---
> O_LARGEFILE |
168c222
< O_BINARY |
---
> O_BINARY |
170,176c224,242
< (state->mode == GZ_READ ?
< O_RDONLY :
< (O_WRONLY | O_CREAT | (
< state->mode == GZ_WRITE ?
< O_TRUNC :
< O_APPEND))),
< 0666);
---
> #ifdef O_CLOEXEC
> (cloexec ? O_CLOEXEC : 0) |
> #endif
> (state->mode == GZ_READ ?
> O_RDONLY :
> (O_WRONLY | O_CREAT |
> #ifdef O_EXCL
> (exclusive ? O_EXCL : 0) |
> #endif
> (state->mode == GZ_WRITE ?
> O_TRUNC :
> O_APPEND)));
>
> /* open the file with the appropriate flags (or just use fd) */
> state->fd = fd > -1 ? fd : (
> #ifdef _WIN32
> fd == -2 ? _wopen(path, oflag, 0666) :
> #endif
> open(path, oflag, 0666));
230a297,306
> #ifdef _WIN32
> gzFile ZEXPORT gzopen_w(path, mode)
> const wchar_t *path;
> const char *mode;
> {
> return gz_open(path, -2, mode);
> }
> #endif
>
> /* -- see zlib.h -- */
249,250c325,326
< if (size == 0)
< return -1;
---
> if (size < 2)
> size = 2; /* need two bytes to check magic header */
267c343,344
< if (state->mode != GZ_READ || state->err != Z_OK)
---
> if (state->mode != GZ_READ ||
> (state->err != Z_OK && state->err != Z_BUF_ERROR))
295c372
< if (state->err != Z_OK)
---
> if (state->err != Z_OK && state->err != Z_BUF_ERROR)
304c381
< offset -= state->pos;
---
> offset -= state->x.pos;
311,312c388,389
< state->pos + offset >= state->raw) {
< ret = LSEEK(state->fd, offset - state->have, SEEK_CUR);
---
> state->x.pos + offset >= 0) {
> ret = LSEEK(state->fd, offset - state->x.have, SEEK_CUR);
315c392
< state->have = 0;
---
> state->x.have = 0;
316a394
> state->past = 0;
320,321c398,399
< state->pos += offset;
< return state->pos;
---
> state->x.pos += offset;
> return state->x.pos;
328c406
< offset += state->pos;
---
> offset += state->x.pos;
337,341c415,419
< n = GT_OFF(state->have) || (z_off64_t)state->have > offset ?
< (unsigned)offset : state->have;
< state->have -= n;
< state->next += n;
< state->pos += n;
---
> n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ?
> (unsigned)offset : state->x.have;
> state->x.have -= n;
> state->x.next += n;
> state->x.pos += n;
350c428
< return state->pos + offset;
---
> return state->x.pos + offset;
379c457
< return state->pos + (state->seek ? state->skip : 0);
---
> return state->x.pos + (state->seek ? state->skip : 0);
439,440c517
< return state->mode == GZ_READ ?
< (state->eof && state->strm.avail_in == 0 && state->have == 0) : 0;
---
> return state->mode == GZ_READ ? state->past : 0;
477c554
< if (state->mode == GZ_READ)
---
> if (state->mode == GZ_READ) {
478a556,557
> state->past = 0;
> }
499a579,582
> /* if fatal, set state->x.have to 0 so that the gzgetc() macro fails */
> if (err != Z_OK && err != Z_BUF_ERROR)
> state->x.have = 0;
>