summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2023-05-07 03:52:23 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2023-05-07 03:52:23 (EDT)
commite473ff37e0febb0c0dda71d6d277cc833bc9f7a3 (patch)
treead233982d1e15be6b444567c2b5a1a550ff71868
parenteb039d67a791638cf000ccec889bdc9026a07fa7 (diff)
gzip: Split init functions
-rw-r--r--src/gzip.c89
-rw-r--r--src/gzip.h4
2 files changed, 47 insertions, 46 deletions
diff --git a/src/gzip.c b/src/gzip.c
index 1263ffc..da4f6a8 100644
--- a/src/gzip.c
+++ b/src/gzip.c
@@ -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
diff --git a/src/gzip.h b/src/gzip.h
index ecf659a..cf017ce 100644
--- a/src/gzip.h
+++ b/src/gzip.h
@@ -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,