]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Attempt to convert the wchar_t path in gzopen_w() for errors.
authorMark Adler <madler@alumni.caltech.edu>
Sun, 18 Mar 2012 21:52:31 +0000 (14:52 -0700)
committerMark Adler <madler@alumni.caltech.edu>
Sun, 18 Mar 2012 21:52:31 +0000 (14:52 -0700)
The conversion to multi-byte will be locale-specific, but it's
better than nothing and is only to provide more information in the
error message returned by gz_error().  The conversion has no
effect on what's opened.

gzlib.c

diff --git a/gzlib.c b/gzlib.c
index e4908e00393f52969e8565ef037d2f714a36b0f4..ca55c6ea9265dbdd07893c190935ca6165f1dd30 100644 (file)
--- a/gzlib.c
+++ b/gzlib.c
@@ -94,6 +94,7 @@ local gzFile gz_open(path, fd, mode)
     const char *mode;
 {
     gz_statep state;
+    size_t len;
     int oflag;
 #ifdef O_CLOEXEC
     int cloexec = 0;
@@ -185,13 +186,29 @@ local gzFile gz_open(path, fd, mode)
     }
 
     /* save the path name for error messages */
-#   define WPATH "<widepath>"
-    state->path = malloc(strlen(fd == -2 ? WPATH : path) + 1);
+#ifdef _WIN32
+    if (fd == -2) {
+        len = wcstombs(NULL, path, 0);
+        if (len == (size_t)-1)
+            len = 0;
+    }
+    else
+#endif
+        len = strlen(path);
+    state->path = malloc(len + 1);
     if (state->path == NULL) {
         free(state);
         return NULL;
     }
-    strcpy(state->path, fd == -2 ? WPATH : path);
+#ifdef _WIN32
+    if (fd == -2)
+        if (len)
+            wcstombs(state->path, path, len + 1);
+        else
+            *(state->path) = 0;
+    else
+#endif
+        strcpy(state->path, path);
 
     /* compute the flags for open() */
     oflag =