diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gzip.c | 89 | ||||
-rw-r--r-- | src/gzip.h | 4 |
2 files changed, 47 insertions, 46 deletions
@@ -41,10 +41,8 @@ struct opkg_opk_gzip { gz_header gz_header; }; -static struct opkg_opk_gzip * -_opkg_opk_gzip_init(enum _opkg_opk_gzip_dir dir, - opkg_opk_gzip_read_func *read_func, - opkg_opk_gzip_write_func *write_func, void *user_data) +struct opkg_opk_gzip * +opkg_opk_gzip_init_read(opkg_opk_gzip_read_func *read_func, void *user_data) { struct opkg_opk_gzip *gzip; @@ -53,61 +51,64 @@ _opkg_opk_gzip_init(enum _opkg_opk_gzip_dir dir, return NULL; } - gzip->dir = dir; + gzip->dir = _OPKG_OPK_GZIP_DIR_READ; gzip->read_func = read_func; - gzip->write_func = write_func; gzip->user_data = user_data; gzip->stream.zalloc = Z_NULL; gzip->stream.zfree = Z_NULL; gzip->stream.opaque = Z_NULL; - if (dir == _OPKG_OPK_GZIP_DIR_READ) { - gzip->stream.next_in = Z_NULL; - gzip->stream.avail_in = 0; - if (inflateInit2(&gzip->stream, OPKG_OPK_GZIP_WINDOW_BITS_) != - Z_OK) { - free(gzip); - return NULL; - } - } else { - gzip->stream.next_out = Z_NULL; - gzip->stream.avail_out = 0; - if (deflateInit2(&gzip->stream, 9, Z_DEFLATED, - OPKG_OPK_GZIP_WINDOW_BITS_, 9, - Z_DEFAULT_STRATEGY) != Z_OK) { - free(gzip); - return NULL; - } - gzip->gz_header.text = 0; - gzip->gz_header.time = 0; /* Stored as 32-bit uint */ - gzip->gz_header.os = 3; /* Unix, per RFC 1952 */ - gzip->gz_header.extra = Z_NULL; - gzip->gz_header.name = Z_NULL; - gzip->gz_header.comment = Z_NULL; - gzip->gz_header.hcrc = 0; - if (deflateSetHeader(&gzip->stream, &gzip->gz_header) != Z_OK) { - deflateEnd(&gzip->stream); - free(gzip); - return NULL; - } + gzip->stream.next_in = Z_NULL; + gzip->stream.avail_in = 0; + if (inflateInit2(&gzip->stream, OPKG_OPK_GZIP_WINDOW_BITS_) != Z_OK) { + free(gzip); + return NULL; } return gzip; } struct opkg_opk_gzip * -opkg_opk_gzip_init_read(opkg_opk_gzip_read_func *read, void *user_data) +opkg_opk_gzip_init_write(opkg_opk_gzip_write_func *write_func, void *user_data) { - return _opkg_opk_gzip_init(_OPKG_OPK_GZIP_DIR_READ, - read, NULL, user_data); -} + struct opkg_opk_gzip *gzip; -struct opkg_opk_gzip * -opkg_opk_gzip_init_write(opkg_opk_gzip_write_func *write, void *user_data) -{ - return _opkg_opk_gzip_init(_OPKG_OPK_GZIP_DIR_WRITE, - NULL, write, user_data); + gzip = malloc(sizeof(*gzip)); + if (gzip == NULL) { + return NULL; + } + + gzip->dir = _OPKG_OPK_GZIP_DIR_WRITE; + gzip->write_func = write_func; + gzip->user_data = user_data; + + gzip->stream.zalloc = Z_NULL; + gzip->stream.zfree = Z_NULL; + gzip->stream.opaque = Z_NULL; + + gzip->stream.next_out = Z_NULL; + gzip->stream.avail_out = 0; + if (deflateInit2(&gzip->stream, 9, Z_DEFLATED, + OPKG_OPK_GZIP_WINDOW_BITS_, 9, + Z_DEFAULT_STRATEGY) != Z_OK) { + free(gzip); + return NULL; + } + gzip->gz_header.text = 0; + gzip->gz_header.time = 0; /* Stored as 32-bit uint */ + gzip->gz_header.os = 3; /* Unix, per RFC 1952 */ + gzip->gz_header.extra = Z_NULL; + gzip->gz_header.name = Z_NULL; + gzip->gz_header.comment = Z_NULL; + gzip->gz_header.hcrc = 0; + if (deflateSetHeader(&gzip->stream, &gzip->gz_header) != Z_OK) { + deflateEnd(&gzip->stream); + free(gzip); + return NULL; + } + + return gzip; } int @@ -42,10 +42,10 @@ typedef int (opkg_opk_gzip_write_func)(void *, size_t); * - NULL on memory exhaustion. */ struct opkg_opk_gzip * -opkg_opk_gzip_init_read(opkg_opk_gzip_read_func *read, void *user_data); +opkg_opk_gzip_init_read(opkg_opk_gzip_read_func *read_func, void *user_data); struct opkg_opk_gzip * -opkg_opk_gzip_init_write(opkg_opk_gzip_write_func *write, void *user_data); +opkg_opk_gzip_init_write(opkg_opk_gzip_write_func *write_func, void *user_data); int opkg_opk_gzip_set_write_buffer(struct opkg_opk_gzip *gzip, char *buffer, |