From e298fe41ac3650bed82ffadc2744e16cba2fb270 Mon Sep 17 00:00:00 2001 From: Robert Pengelly Date: Wed, 1 Oct 2025 20:38:26 +0100 Subject: [PATCH] Covert '/' to '\' when built for Windows --- unzip.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/unzip.c b/unzip.c index b0a2736..44fd25d 100755 --- 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); -- 2.34.1