unneeded compression or decompression routines. */
int ZEXPORT gzclose(gzFile file) {
#ifndef NO_GZCOMPRESS
- gz_statep state;
+ gz_state *state;
if (file == NULL)
return Z_STREAM_ERROR;
- state = (gz_statep)file;
+ state = (gz_state *)file;
return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file);
#else
typedef gz_state *gz_statep;
/* shared functions */
-void ZLIB_INTERNAL gz_error(gz_statep, int, const char *);
+void ZLIB_INTERNAL gz_error(gz_state *, int, const char *);
/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
value -- needed when comparing unsigned to z_off64_t, which is signed
#endif
/* Local functions */
-static void gz_reset(gz_statep);
+static void gz_reset(gz_state *);
static gzFile gz_open(const void *, int, const char *);
/* Reset gzip file state */
-static void gz_reset(gz_statep state) {
+static void gz_reset(gz_state *state) {
state->x.have = 0; /* no output data available */
if (state->mode == GZ_READ) { /* for reading ... */
state->eof = 0; /* not at end of file */
/* Open a gzip file either by name or file descriptor. */
static gzFile gz_open(const void *path, int fd, const char *mode) {
- gz_statep state;
+ gz_state *state;
size_t len;
int oflag;
#ifdef O_CLOEXEC
return NULL;
/* allocate gzFile structure to return */
- state = (gz_statep)malloc(sizeof(gz_state));
+ state = (gz_state *)malloc(sizeof(gz_state));
if (state == NULL)
return NULL;
state->size = 0; /* no buffers allocated yet */
/* -- see zlib.h -- */
int ZEXPORT gzbuffer(gzFile file, unsigned size) {
- gz_statep state;
+ gz_state *state;
/* get internal structure and check integrity */
if (file == NULL)
return -1;
- state = (gz_statep)file;
+ state = (gz_state *)file;
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
return -1;
/* -- see zlib.h -- */
int ZEXPORT gzrewind(gzFile file) {
- gz_statep state;
+ gz_state *state;
/* get internal structure */
if (file == NULL)
return -1;
- state = (gz_statep)file;
+ state = (gz_state *)file;
/* check that we're reading and that there's no error */
if (state->mode != GZ_READ || (state->err != Z_OK && state->err != Z_BUF_ERROR))
z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
unsigned n;
z_off64_t ret;
- gz_statep state;
+ gz_state *state;
/* get internal structure and check integrity */
if (file == NULL)
return -1;
- state = (gz_statep)file;
+ state = (gz_state *)file;
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
return -1;
/* -- see zlib.h -- */
z_off64_t ZEXPORT gztell64(gzFile file) {
- gz_statep state;
+ gz_state *state;
/* get internal structure and check integrity */
if (file == NULL)
return -1;
- state = (gz_statep)file;
+ state = (gz_state *)file;
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
return -1;
/* -- see zlib.h -- */
z_off64_t ZEXPORT gzoffset64(gzFile file) {
z_off64_t offset;
- gz_statep state;
+ gz_state *state;
/* get internal structure and check integrity */
if (file == NULL)
return -1;
- state = (gz_statep)file;
+ state = (gz_state *)file;
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
return -1;
/* -- see zlib.h -- */
int ZEXPORT gzeof(gzFile file) {
- gz_statep state;
+ gz_state *state;
/* get internal structure and check integrity */
if (file == NULL)
return 0;
- state = (gz_statep)file;
+ state = (gz_state *)file;
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
return 0;
/* -- see zlib.h -- */
const char * ZEXPORT gzerror(gzFile file, int *errnum) {
- gz_statep state;
+ gz_state *state;
/* get internal structure and check integrity */
if (file == NULL)
return NULL;
- state = (gz_statep)file;
+ state = (gz_state *)file;
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
return NULL;
/* -- see zlib.h -- */
void ZEXPORT gzclearerr(gzFile file) {
- gz_statep state;
+ gz_state *state;
/* get internal structure and check integrity */
if (file == NULL)
return;
- state = (gz_statep)file;
+ state = (gz_state *)file;
if (state->mode != GZ_READ && state->mode != GZ_WRITE)
return;
memory). Simply save the error message as a static string. If there is an
allocation failure constructing the error message, then convert the error to
out of memory. */
-void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg) {
+void ZLIB_INTERNAL gz_error(gz_state *state, int err, const char *msg) {
/* free previously allocated message and clear */
if (state->msg != NULL) {
if (state->err != Z_MEM_ERROR)
#include "gzguts.h"
/* Local functions */
-static int gz_load(gz_statep, unsigned char *, unsigned, unsigned *);
-static int gz_avail(gz_statep);
-static int gz_look(gz_statep);
-static int gz_decomp(gz_statep);
-static int gz_fetch(gz_statep);
-static int gz_skip(gz_statep, z_off64_t);
-static size_t gz_read(gz_statep, void *, size_t);
+static int gz_load(gz_state *, unsigned char *, unsigned, unsigned *);
+static int gz_avail(gz_state *);
+static int gz_look(gz_state *);
+static int gz_decomp(gz_state *);
+static int gz_fetch(gz_state *);
+static int gz_skip(gz_state *, z_off64_t);
+static size_t gz_read(gz_state *, void *, size_t);
/* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from
state->fd, and update state->eof, state->err, and state->msg as appropriate.
This function needs to loop on read(), since read() is not guaranteed to
read the number of bytes requested, depending on the type of descriptor. */
-static int gz_load(gz_statep state, unsigned char *buf, unsigned len, unsigned *have) {
+static int gz_load(gz_state *state, unsigned char *buf, unsigned len, unsigned *have) {
ssize_t ret;
*have = 0;
If strm->avail_in != 0, then the current data is moved to the beginning of
the input buffer, and then the remainder of the buffer is loaded with the
available data from the input file. */
-static int gz_avail(gz_statep state) {
+static int gz_avail(gz_state *state) {
unsigned got;
z_stream *strm = &(state->strm);
case, all further file reads will be directly to either the output buffer or
a user buffer. If decompressing, the inflate state will be initialized.
gz_look() will return 0 on success or -1 on failure. */
-static int gz_look(gz_statep state) {
+static int gz_look(gz_state *state) {
z_stream *strm = &(state->strm);
/* allocate read buffers and inflate memory */
data. If the gzip stream completes, state->how is reset to LOOK to look for
the next gzip stream or raw data, once state->x.have is depleted. Returns 0
on success, -1 on failure. */
-static int gz_decomp(gz_statep state) {
+static int gz_decomp(gz_state *state) {
int ret = Z_OK;
unsigned had;
z_stream *strm = &(state->strm);
looked for to determine whether to copy or decompress. Returns -1 on error,
otherwise 0. gz_fetch() will leave state->how as COPY or GZIP unless the
end of the input file has been reached and all data has been processed. */
-static int gz_fetch(gz_statep state) {
+static int gz_fetch(gz_state *state) {
z_stream *strm = &(state->strm);
do {
}
/* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */
-static int gz_skip(gz_statep state, z_off64_t len) {
+static int gz_skip(gz_state *state, z_off64_t len) {
unsigned n;
/* skip over len bytes or reach end-of-file, whichever comes first */
input. Return the number of bytes read. If zero is returned, either the
end of file was reached, or there was an error. state->err must be
consulted in that case to determine which. */
-static size_t gz_read(gz_statep state, void *buf, size_t len) {
+static size_t gz_read(gz_state *state, void *buf, size_t len) {
size_t got;
unsigned n;
/* -- see zlib.h -- */
int ZEXPORT gzread(gzFile file, void *buf, unsigned len) {
- gz_statep state;
+ gz_state *state;
/* get internal structure */
if (file == NULL)
return -1;
- state = (gz_statep)file;
+ state = (gz_state *)file;
/* check that we're reading and that there's no (serious) error */
if (state->mode != GZ_READ ||
/* -- see zlib.h -- */
size_t ZEXPORT gzfread(void *buf, size_t size, size_t nitems, gzFile file) {
size_t len;
- gz_statep state;
+ gz_state *state;
/* get internal structure */
if (file == NULL)
return 0;
- state = (gz_statep)file;
+ state = (gz_state *)file;
/* check that we're reading and that there's no (serious) error */
if (state->mode != GZ_READ ||
int ZEXPORT gzgetc(gzFile file) {
int ret;
unsigned char buf[1];
- gz_statep state;
+ gz_state *state;
/* get internal structure */
if (file == NULL)
return -1;
- state = (gz_statep)file;
+ state = (gz_state *)file;
/* check that we're reading and that there's no (serious) error */
if (state->mode != GZ_READ || (state->err != Z_OK && state->err != Z_BUF_ERROR))
/* -- see zlib.h -- */
int ZEXPORT gzungetc(int c, gzFile file) {
- gz_statep state;
+ gz_state *state;
/* get internal structure */
if (file == NULL)
return -1;
- state = (gz_statep)file;
+ state = (gz_state *)file;
/* check that we're reading and that there's no (serious) error */
if (state->mode != GZ_READ || (state->err != Z_OK && state->err != Z_BUF_ERROR))
unsigned left, n;
char *str;
unsigned char *eol;
- gz_statep state;
+ gz_state *state;
/* check parameters and get internal structure */
if (file == NULL || buf == NULL || len < 1)
return NULL;
- state = (gz_statep)file;
+ state = (gz_state *)file;
/* check that we're reading and that there's no (serious) error */
if (state->mode != GZ_READ || (state->err != Z_OK && state->err != Z_BUF_ERROR))
/* -- see zlib.h -- */
int ZEXPORT gzdirect(gzFile file) {
- gz_statep state;
+ gz_state *state;
/* get internal structure */
if (file == NULL)
return 0;
- state = (gz_statep)file;
+ state = (gz_state *)file;
/* if the state is not known, but we can find out, then do so (this is
mainly for right after a gzopen() or gzdopen()) */
/* -- see zlib.h -- */
int ZEXPORT gzclose_r(gzFile file) {
int ret, err;
- gz_statep state;
+ gz_state *state;
/* get internal structure */
if (file == NULL)
return Z_STREAM_ERROR;
- state = (gz_statep)file;
+ state = (gz_state *)file;
/* check that we're reading */
if (state->mode != GZ_READ)
#include "gzguts.h"
/* Local functions */
-static int gz_init(gz_statep);
-static int gz_comp(gz_statep, int);
-static int gz_zero(gz_statep, z_off64_t);
-static size_t gz_write(gz_statep, void const *, size_t);
+static int gz_init(gz_state *);
+static int gz_comp(gz_state *, int);
+static int gz_zero(gz_state *, z_off64_t);
+static size_t gz_write(gz_state *, void const *, size_t);
/* Initialize state for writing a gzip file. Mark initialization by setting
state->size to non-zero. Return -1 on a memory allocation failure, or 0 on
success. */
-static int gz_init(gz_statep state) {
+static int gz_init(gz_state *state) {
int ret;
z_stream *strm = &(state->strm);
deflate() flush value. If flush is Z_FINISH, then the deflate() state is
reset to start a new gzip stream. If gz->direct is true, then simply write
to the output file without compressing, and ignore flush. */
-static int gz_comp(gz_statep state, int flush) {
+static int gz_comp(gz_state *state, int flush) {
int ret;
ssize_t got;
unsigned have;
/* Compress len zeros to output. Return -1 on a write error or memory
allocation failure by gz_comp(), or 0 on success. */
-static int gz_zero(gz_statep state, z_off64_t len) {
+static int gz_zero(gz_state *state, z_off64_t len) {
int first;
unsigned n;
z_stream *strm = &(state->strm);
/* Write len bytes from buf to file. Return the number of bytes written. If
the returned value is less than len, then there was an error. */
-static size_t gz_write(gz_statep state, void const *buf, size_t len) {
+static size_t gz_write(gz_state *state, void const *buf, size_t len) {
size_t put = len;
/* if len is zero, avoid unnecessary operations */
/* -- see zlib.h -- */
int ZEXPORT gzwrite(gzFile file, void const *buf, unsigned len) {
- gz_statep state;
+ gz_state *state;
/* get internal structure */
if (file == NULL)
return 0;
- state = (gz_statep)file;
+ state = (gz_state *)file;
/* check that we're writing and that there's no error */
if (state->mode != GZ_WRITE || state->err != Z_OK)
/* -- see zlib.h -- */
size_t ZEXPORT gzfwrite(void const *buf, size_t size, size_t nitems, gzFile file) {
size_t len;
- gz_statep state;
+ gz_state *state;
/* get internal structure */
if (file == NULL)
return 0;
- state = (gz_statep)file;
+ state = (gz_state *)file;
/* check that we're writing and that there's no error */
if (state->mode != GZ_WRITE || state->err != Z_OK)
int ZEXPORT gzputc(gzFile file, int c) {
unsigned have;
unsigned char buf[1];
- gz_statep state;
+ gz_state *state;
z_stream *strm;
/* get internal structure */
if (file == NULL)
return -1;
- state = (gz_statep)file;
+ state = (gz_state *)file;
strm = &(state->strm);
/* check that we're writing and that there's no error */
int ZEXPORT gzputs(gzFile file, const char *str) {
int ret;
size_t len;
- gz_statep state;
+ gz_state *state;
/* get internal structure */
if (file == NULL)
return -1;
- state = (gz_statep)file;
+ state = (gz_state *)file;
/* check that we're writing and that there's no error */
if (state->mode != GZ_WRITE || state->err != Z_OK)
int len;
unsigned left;
char *next;
- gz_statep state;
+ gz_state *state;
z_stream *strm;
/* get internal structure */
if (file == NULL)
return Z_STREAM_ERROR;
- state = (gz_statep)file;
+ state = (gz_state *)file;
strm = &(state->strm);
/* check that we're writing and that there's no error */
/* -- see zlib.h -- */
int ZEXPORT gzflush(gzFile file, int flush) {
- gz_statep state;
+ gz_state *state;
/* get internal structure */
if (file == NULL)
return Z_STREAM_ERROR;
- state = (gz_statep)file;
+ state = (gz_state *)file;
/* check that we're writing and that there's no error */
if (state->mode != GZ_WRITE || state->err != Z_OK)
/* -- see zlib.h -- */
int ZEXPORT gzsetparams(gzFile file, int level, int strategy) {
- gz_statep state;
+ gz_state *state;
z_stream *strm;
/* get internal structure */
if (file == NULL)
return Z_STREAM_ERROR;
- state = (gz_statep)file;
+ state = (gz_state *)file;
strm = &(state->strm);
/* check that we're writing and that there's no error */
/* -- see zlib.h -- */
int ZEXPORT gzclose_w(gzFile file) {
int ret = Z_OK;
- gz_statep state;
+ gz_state *state;
/* get internal structure */
if (file == NULL)
return Z_STREAM_ERROR;
- state = (gz_statep)file;
+ state = (gz_state *)file;
/* check that we're writing */
if (state->mode != GZ_WRITE)