From 0f96542e7c0f0555b2b2ef7ac52c574a616fa7b2 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Mon, 17 Apr 2023 10:44:37 -0400 Subject: ustar: Search for multiple member names --- diff --git a/TODO b/TODO index 0003f4d..95eefcf 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,3 @@ -Make `opkg_opk_ustar_seek()` accept a (varargs) list of possible member names Add missing ustar member fields Add option handling I18n? diff --git a/src/main.c b/src/main.c index d2f513b..d400934 100644 --- a/src/main.c +++ b/src/main.c @@ -76,7 +76,7 @@ _opkg_opk_main_extract(const char *file_name, const char *outer_member, goto error2; } - if (opkg_opk_ustar_seek(outer_ustar, outer_member) != OPKG_OPK_OK) { + if (opkg_opk_ustar_seek(outer_ustar, 1, outer_member) != OPKG_OPK_OK) { fprintf(stderr, "Error: Failed to find \"%s\" in archive\n", outer_member); goto error3; @@ -128,7 +128,8 @@ _opkg_opk_main_read_control(struct opkg_opk_ustar *ustar) size_t size; int ret; - if (opkg_opk_ustar_seek(ustar, "./control") != OPKG_OPK_OK) { + if (opkg_opk_ustar_seek(ustar, 2, "control", "./control") != + OPKG_OPK_OK) { fputs("Error: Failed to find control file\n", stderr); return OPKG_OPK_ERROR; } diff --git a/src/ustar.c b/src/ustar.c index 21d41eb..d728cf5 100644 --- a/src/ustar.c +++ b/src/ustar.c @@ -17,6 +17,7 @@ * along with opkg-opk. If not, see . */ +#include #include #include #include @@ -128,10 +129,13 @@ opkg_opk_ustar_list(struct opkg_opk_ustar *ustar, } int -opkg_opk_ustar_seek(struct opkg_opk_ustar *ustar, const char *member) +opkg_opk_ustar_seek(struct opkg_opk_ustar *ustar, int num_keys, ...) { static struct _opkg_opk_ustar_header header; static unsigned char name[OPKG_OPK_USTAR_NAME_MAX_LEN]; + va_list ap; + int key; + const char *member; for (;;) { if (_opkg_opk_ustar_next(ustar, &header) != OPKG_OPK_OK) { @@ -146,9 +150,14 @@ opkg_opk_ustar_seek(struct opkg_opk_ustar *ustar, const char *member) name[sizeof(header.name)] = '\0'; } - if (strcmp((char *) name, member) == 0) { - return OPKG_OPK_OK; /* Member found */ + va_start(ap, num_keys); + for (key = 0; key < num_keys; ++key) { + member = va_arg(ap, const char *); + if (strcmp((char *) name, member) == 0) { + return OPKG_OPK_OK; /* Member found */ + } } + va_end(ap); while (ustar->data_size_remaining > 0) { if (opkg_opk_ustar_read(ustar, NULL, NULL) == diff --git a/src/ustar.h b/src/ustar.h index d199063..de782b8 100644 --- a/src/ustar.h +++ b/src/ustar.h @@ -38,7 +38,7 @@ opkg_opk_ustar_list(struct opkg_opk_ustar *ustar, struct opkg_opk_ustar_member *member); int -opkg_opk_ustar_seek(struct opkg_opk_ustar *ustar, const char *member); +opkg_opk_ustar_seek(struct opkg_opk_ustar *ustar, int num_keys, ...); int opkg_opk_ustar_read(struct opkg_opk_ustar *ustar, char **buffer, size_t *size); -- cgit v0.9.1