Covert '/' to '\' when built for Windows
authorRobert Pengelly <robertapengelly@hotmail.com>
Wed, 1 Oct 2025 19:38:26 +0000 (20:38 +0100)
committerRobert Pengelly <robertapengelly@hotmail.com>
Wed, 1 Oct 2025 19:38:26 +0000 (20:38 +0100)
unzip.c

diff --git a/unzip.c b/unzip.c
index b0a273646e63e2e88f2f71601c2235a279477ac8..44fd25d8a17f787d060bbaeaec649f4e12442029 100755 (executable)
--- a/unzip.c
+++ b/unzip.c
@@ -691,7 +691,17 @@ static void extract_zip (const char *path) {
         
         }
         
-        if (cfh.ext_attrs & EXT_ATTR_DIR || (p = strrchr (cfh.name, '/'))) {
+        p = cfh.name;
+        
+#if     defined (_WIN32)
+
+        while ((p = strchr (p, '/'))) {
+            *p++ = '\\';
+        }
+
+#endif
+        
+        if (cfh.ext_attrs & EXT_ATTR_DIR || (p = strrchr (cfh.name, ch))) {
         
             if (p) { *p = '\0'; }
             
@@ -701,7 +711,7 @@ static void extract_zip (const char *path) {
                 
                     report_at (program_name, 0, REPORT_ERROR, "not enough free memory for name");
                     
-                    if (p) { *p = '/'; }
+                    if (p) { *p = ch; }
                     break;
                 
                 }
@@ -727,7 +737,7 @@ static void extract_zip (const char *path) {
                 
                     report_at (program_name, 0, REPORT_ERROR, "not enough free memory for name");
                     
-                    if (p) { *p = '/'; }
+                    if (p) { *p = ch; }
                     break;
                 
                 }
@@ -749,6 +759,10 @@ static void extract_zip (const char *path) {
             
             }
             
+            if (temp[strlen (temp) - 1] == ch) {
+                temp[strlen (temp) - 1] = '\0';
+            }
+            
 #if     defined (unix) || defined (__unix) || defined (__unix__) || defined (__APPLE__)
 
             if (!stat (temp, &sb)) {
@@ -779,10 +793,10 @@ static void extract_zip (const char *path) {
                     free (temp);
                     break;
                 
-                } else {
-                    printf ("   creating: %s%c\n", temp, ch);
                 }
             
+            } else {
+                printf ("   creating: %s%c\n", temp, ch);
             }
 
 #endif
@@ -796,10 +810,10 @@ static void extract_zip (const char *path) {
             
             }
             
-            if (p) { *p = '/'; }
+            if (p) { *p = ch; }
             free (temp);
             
-            if (cfh.ext_attrs & EXT_ATTR_DIR || cfh.name[cfh.name_len - 1] == '/') {
+            if (cfh.ext_attrs & EXT_ATTR_DIR || cfh.name[cfh.name_len - 1] == ch) {
             
                 free (cfh.name);