From 24d160031389fe295cc338eea3dddbb415c43247 Mon Sep 17 00:00:00 2001 From: Ayabusa Date: Thu, 11 Jun 2026 20:27:56 +0200 Subject: [PATCH] fixed some stuff in the unzip utility --- src/unzip.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/unzip.c b/src/unzip.c index 7b678b8..1c27f4e 100644 --- a/src/unzip.c +++ b/src/unzip.c @@ -8,6 +8,7 @@ #include #include #include "unzip.h" +#include "path.h" // Thank gosh I found this ref : https://gist.github.com/mobius/1759816 @@ -26,18 +27,10 @@ int zip_extract_to(char *zip_path, char *extract_loc) { int err; char buf[100]; - extract_loc = strdup(extract_loc); - int extract_loc_len = strlen(extract_loc); - if (extract_loc[extract_loc_len - 1] != '/') { - extract_loc = realloc(extract_loc, extract_loc_len + 2); - extract_loc[extract_loc_len] = '/'; - extract_loc[extract_loc_len + 1] = '\0'; - } - if ((za = zip_open(zip_path, 0, &err)) == NULL) { - zip_error_to_str(buf, sizeof(buf), err, errno); - fprintf(stderr, "Failed to open zip archive `%s': %s\n", zip_path, buf); - return 1; + const char *error = zip_strerror(za); + fprintf(stderr, "Failed to open zip archive `%s': %s\n", zip_path, error); + exit(1); } for (int i = 0; i < zip_get_num_entries(za, 0); i++) { @@ -45,10 +38,8 @@ int zip_extract_to(char *zip_path, char *extract_loc) { if (!zip_stat_index(za, i, 0, &sb)) { int len = strlen(sb.name); - char *name = calloc(1, extract_loc_len + len + 2); - strcpy(name, extract_loc); - strcat(name, sb.name); - + path name = init_path(extract_loc); + cat_path(name, (const path)sb.name); len = strlen(name); if (name[len - 1] == '/') @@ -70,6 +61,7 @@ int zip_extract_to(char *zip_path, char *extract_loc) { free(name); } else { printf("Oopsie, Iv got some error while extracting the file %s\n", __FILE__); + exit(1); } } free(extract_loc); -- 2.43.0