#include "gzguts.h"
/* Local functions */
+static int gz_read_init(gz_state *state);
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_skip(gz_state *, z_off64_t);
static size_t gz_read(gz_state *, void *, size_t);
+static int gz_read_init(gz_state *state) {
+ /* Allocate gz buffers */
+ if (gz_buffer_alloc(state) != 0)
+ return -1;
+
+ /* Initialize inflate state */
+ if (PREFIX(inflateInit2)(&(state->strm), MAX_WBITS + 16) != Z_OK) {
+ gz_buffer_free(state);
+ gz_error(state, Z_MEM_ERROR, "out of memory");
+ return -1;
+ }
+ return 0;
+}
+
/* 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
static int gz_look(gz_state *state) {
PREFIX3(stream) *strm = &(state->strm);
- if (state->size == 0) {
- /* Allocate gz buffers */
- if (gz_buffer_alloc(state) != 0) {
- return -1;
- }
-
- /* Initialize inflate state */
- if (PREFIX(inflateInit2)(&(state->strm), MAX_WBITS + 16) != Z_OK) { /* gunzip */
- gz_buffer_free(state);
- gz_error(state, Z_MEM_ERROR, "out of memory");
- return -1;
- }
- }
+ /* allocate memory if this is the first time through */
+ if (state->size == 0 && gz_read_init(state) == -1)
+ return -1;
/* get at least the magic bytes in the input buffer */
if (strm->avail_in < 2) {
#include "gzguts.h"
/* Local functions */
-static int gz_init(gz_state *);
+static int gz_write_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_state *state) {
+static int gz_write_init(gz_state *state) {
int ret;
PREFIX3(stream) *strm = &(state->strm);
}
/* Compress whatever is at avail_in and next_in and write to the output file.
- Return -1 if there is an error writing to the output file or if gz_init()
+ Return -1 if there is an error writing to the output file or if gz_write_init()
fails to allocate memory, otherwise 0. flush is assumed to be a valid
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
PREFIX3(stream) *strm = &(state->strm);
/* allocate memory if this is the first time through */
- if (state->size == 0 && gz_init(state) == -1)
+ if (state->size == 0 && gz_write_init(state) == -1)
return -1;
/* write directly if requested */
return 0;
/* allocate memory if this is the first time through */
- if (state->size == 0 && gz_init(state) == -1)
+ if (state->size == 0 && gz_write_init(state) == -1)
return 0;
/* check for seek request */
return Z_STREAM_ERROR;
/* make sure we have some buffer space */
- if (state->size == 0 && gz_init(state) == -1)
+ if (state->size == 0 && gz_write_init(state) == -1)
return state->err;
/* check for seek request */