summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2023-04-15 18:04:25 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2023-04-15 18:04:25 (EDT)
commite707a8fa42f8b9a2d75fd22678f7431ef1323589 (patch)
treebefddd581e34c7379362f144dcf32a026c227355
parent3c3612d0eaec5f9b6c3c1596f43b395ad5cdcd80 (diff)
main: Simplify/improve error handling
-rw-r--r--src/main.c43
1 files changed, 25 insertions, 18 deletions
diff --git a/src/main.c b/src/main.c
index 7d554f5..a24f3de 100644
--- a/src/main.c
+++ b/src/main.c
@@ -59,49 +59,56 @@ _opkg_opk_main_extract(const char *file_name, const char *outer_member,
file.file = fopen(file_name, "rb");
if (file.file == NULL) {
- return OPKG_OPK_ERROR;
+ goto error0;
}
outer_gzip = opkg_opk_gzip_init(&_opkg_opk_main_file_read, &file);
if (outer_gzip == NULL) {
- fclose(file.file);
- return OPKG_OPK_ERROR;
+ goto error1;
}
outer_ustar = opkg_opk_ustar_init(outer_gzip);
if (outer_ustar == NULL) {
- opkg_opk_gzip_free(outer_gzip);
- fclose(file.file);
- return OPKG_OPK_ERROR;
+ goto error2;
+ }
+
+ if (opkg_opk_ustar_seek(outer_ustar, outer_member) != OPKG_OPK_OK) {
+ goto error3;
}
- opkg_opk_ustar_seek(outer_ustar, outer_member);
inner_gzip = opkg_opk_gzip_init(&opkg_opk_ustar_read, outer_ustar);
if (inner_gzip == NULL) {
- opkg_opk_ustar_free(outer_ustar);
- opkg_opk_gzip_free(outer_gzip);
- fclose(file.file);
- return OPKG_OPK_ERROR;
+ goto error3;
}
inner_ustar = opkg_opk_ustar_init(inner_gzip);
if (inner_ustar == NULL) {
- opkg_opk_gzip_free(inner_gzip);
- opkg_opk_ustar_free(outer_ustar);
- opkg_opk_gzip_free(outer_gzip);
- fclose(file.file);
- return OPKG_OPK_ERROR;
+ goto error4;
}
- inner_action(inner_ustar);
+ if (inner_action(inner_ustar) != OPKG_OPK_OK) {
+ goto error5;
+ }
opkg_opk_ustar_free(inner_ustar);
opkg_opk_gzip_free(inner_gzip);
opkg_opk_ustar_free(outer_ustar);
opkg_opk_gzip_free(outer_gzip);
fclose(file.file);
-
return OPKG_OPK_OK;
+
+ error5:
+ opkg_opk_ustar_free(inner_ustar);
+ error4:
+ opkg_opk_gzip_free(inner_gzip);
+ error3:
+ opkg_opk_ustar_free(outer_ustar);
+ error2:
+ opkg_opk_gzip_free(outer_gzip);
+ error1:
+ fclose(file.file);
+ error0:
+ return OPKG_OPK_ERROR;
}
static int