]> git.ayabusa.dev Git - thoryum.git/commitdiff
fixed some stuff in the unzip utility
authorAyabusa <lebgpub@gmail.com>
Thu, 11 Jun 2026 18:27:56 +0000 (20:27 +0200)
committerAyabusa <lebgpub@gmail.com>
Thu, 11 Jun 2026 18:27:56 +0000 (20:27 +0200)
src/unzip.c

index 7b678b8cd9045ff1264ba85d3e051c35593d71a5..1c27f4e09ff55f9d3db243ba4dc395b88b655b79 100644 (file)
@@ -8,6 +8,7 @@
 #include <unistd.h>
 #include <stdlib.h>
 #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);