summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2023-04-13 18:40:49 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2023-04-14 14:37:17 (EDT)
commitea566435355699cab1d3db3343cf6996c281f2f2 (patch)
tree138fe7c7795c60cfccbf93d8c148ddae0d5cb210
parent5f1a4ab4c2ff4055e3a784d5f521e102435341bd (diff)
main: List outer archive members
-rw-r--r--src/main.c54
1 files changed, 49 insertions, 5 deletions
diff --git a/src/main.c b/src/main.c
index 5d72ba1..26e60fa 100644
--- a/src/main.c
+++ b/src/main.c
@@ -17,18 +17,62 @@
* along with opkg-opk. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <stdio.h>
#include <stdlib.h>
+#include "defs.h"
#include "gzip.h"
#include "ustar.h"
+struct _opkg_opk_main_file {
+ FILE *file;
+ char buffer[8192];
+};
+
+static int
+_opkg_opk_main_file_read(void *user_data, char **buffer, size_t *size)
+{
+ struct _opkg_opk_main_file *file = user_data;
+
+ *buffer = file->buffer;
+ *size = fread(file->buffer, 1, 8192, file->file);
+ if (feof(file->file)) {
+ return OPKG_OPK_END;
+ } else if (ferror(file->file) || *size == 0) {
+ return OPKG_OPK_ERROR;
+ } else {
+ return OPKG_OPK_OK;
+ }
+}
+
int
main(int argc, char *argv[])
{
- struct opkg_opk_gzip_state gzip_state;
+ struct _opkg_opk_main_file file;
+ struct opkg_opk_gzip *gzip;
+ struct opkg_opk_ustar *ustar;
+ struct opkg_opk_ustar_member member;
+ int ret;
- opkg_opk_gzip_init_from_file(&gzip_state, argv[1]);
- opkg_opk_ustar_list(&gzip_state, NULL);
- inflateEnd(&gzip_state.stream);
+ file.file = fopen(argv[1], "rb");
+ if (file.file == NULL) {
+ return EXIT_FAILURE;
+ }
+ gzip = opkg_opk_gzip_init(&_opkg_opk_main_file_read, &file);
+ if (gzip == NULL) {
+ fclose(file.file);
+ return EXIT_FAILURE;
+ }
+ ustar = opkg_opk_ustar_init(gzip);
+ if (ustar == NULL) {
+ /* TODO: Free gzip. */
+ fclose(file.file);
+ return EXIT_FAILURE;
+ }
+ while ((ret = opkg_opk_ustar_list(ustar, &member)) == OPKG_OPK_OK) {
+ puts(member.name);
+ }
+ /* TODO: Free ustar and gzip. */
+ fclose(file.file);
- return 0;
+ return EXIT_SUCCESS;
}