summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/defs.h27
-rw-r--r--src/gzip.c27
-rw-r--r--src/gzip.h4
-rw-r--r--src/local.mk1
4 files changed, 42 insertions, 17 deletions
diff --git a/src/defs.h b/src/defs.h
new file mode 100644
index 0000000..676640c
--- /dev/null
+++ b/src/defs.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2023 Patrick McDermott
+ *
+ * This file is part of opkg-opk.
+ *
+ * opkg-opk is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * opkg-opk is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with opkg-opk. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef OPKG_OPK_DEFS_H_
+#define OPKG_OPK_DEFS_H_
+
+#define OPKG_OPK_OK 0
+#define OPKG_OPK_END 1
+#define OPKG_OPK_ERROR -1
+
+#endif /* OPKG_OPK_DEFS_H_ */
diff --git a/src/gzip.c b/src/gzip.c
index 328f33a..05d4065 100644
--- a/src/gzip.c
+++ b/src/gzip.c
@@ -19,6 +19,7 @@
#include <stdio.h>
#include <zlib.h>
+#include "defs.h"
#include "gzip.h"
#define OPKG_OPK_GZIP_BUFFER_SIZE 8192
@@ -36,9 +37,9 @@ _opkg_opk_gzip_init(struct opkg_opk_gzip_state *state)
state->stream.zfree = Z_NULL;
state->stream.opaque = Z_NULL;
if (inflateInit(&state->stream) != Z_OK) {
- return OPKG_OPK_GZIP_ERROR;
+ return OPKG_OPK_ERROR;
}
- return OPKG_OPK_GZIP_OK;
+ return OPKG_OPK_OK;
}
int
@@ -47,15 +48,15 @@ opkg_opk_gzip_init_from_file(struct opkg_opk_gzip_state *state,
{
state->input_file = fopen(file_name, "rb");
if (state->input_file == NULL) {
- return OPKG_OPK_GZIP_ERROR;
+ return OPKG_OPK_ERROR;
}
state->stream.next_in = Z_NULL;
state->stream.avail_in = 0;
- if (_opkg_opk_gzip_init(state) < OPKG_OPK_GZIP_OK) {
+ if (_opkg_opk_gzip_init(state) < OPKG_OPK_OK) {
fclose(state->input_file);
- return OPKG_OPK_GZIP_ERROR;
+ return OPKG_OPK_ERROR;
}
- return OPKG_OPK_GZIP_OK;
+ return OPKG_OPK_OK;
}
int
@@ -76,7 +77,7 @@ _opkg_opk_gzip_next_record_from_file(struct opkg_opk_gzip_state *state)
fclose(state->input_file);
state->input_file = NULL;
inflateEnd(&state->stream);
- return OPKG_OPK_GZIP_OK;
+ return OPKG_OPK_OK;
}
if (state->stream.avail_in == 0) {
state->stream.avail_in = fread(state->input_buffer,
@@ -86,12 +87,12 @@ _opkg_opk_gzip_next_record_from_file(struct opkg_opk_gzip_state *state)
fclose(state->input_file);
state->input_file = NULL;
inflateEnd(&state->stream);
- return OPKG_OPK_GZIP_ERROR;
+ return OPKG_OPK_ERROR;
}
state->stream.next_in = state->input_buffer;
}
if (state->stream.avail_out == 0) {
- return OPKG_OPK_GZIP_OK;
+ return OPKG_OPK_OK;
}
switch (inflate(&state->stream, Z_SYNC_FLUSH)) {
case Z_OK:
@@ -102,7 +103,7 @@ _opkg_opk_gzip_next_record_from_file(struct opkg_opk_gzip_state *state)
fclose(state->input_file);
state->input_file = NULL;
inflateEnd(&state->stream);
- return OPKG_OPK_GZIP_ERROR;
+ return OPKG_OPK_ERROR;
}
}
}
@@ -112,12 +113,12 @@ _opkg_opk_gzip_next_record_from_memory(struct opkg_opk_gzip_state *state)
{
switch (inflate(&state->stream, Z_SYNC_FLUSH)) {
case Z_OK:
- return OPKG_OPK_GZIP_OK;
+ return OPKG_OPK_OK;
case Z_STREAM_END:
- return OPKG_OPK_GZIP_END;
+ return OPKG_OPK_END;
default:
inflateEnd(&state->stream);
- return OPKG_OPK_GZIP_ERROR;
+ return OPKG_OPK_ERROR;
}
}
diff --git a/src/gzip.h b/src/gzip.h
index 5a3b2c7..53563e8 100644
--- a/src/gzip.h
+++ b/src/gzip.h
@@ -22,10 +22,6 @@
struct opkg_opk_gzip_state;
-#define OPKG_OPK_GZIP_OK 0
-#define OPKG_OPK_GZIP_END 1
-#define OPKG_OPK_GZIP_ERROR -1
-
int
opkg_opk_gzip_init_from_file(struct opkg_opk_gzip_state *state,
const char *file_name);
diff --git a/src/local.mk b/src/local.mk
index 18c6181..a3ebaf1 100644
--- a/src/local.mk
+++ b/src/local.mk
@@ -1,4 +1,5 @@
opkg_opk_SOURCES += \
+ %reldir%/defs.h \
%reldir%/gzip.c \
%reldir%/gzip.h \
%reldir%/main.c