aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gzlib.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/gzlib.c b/gzlib.c
index e4908e0..ca55c6e 100644
--- a/gzlib.c
+++ b/gzlib.c
@@ -94,6 +94,7 @@ local gzFile gz_open(path, fd, mode)
94 const char *mode; 94 const char *mode;
95{ 95{
96 gz_statep state; 96 gz_statep state;
97 size_t len;
97 int oflag; 98 int oflag;
98#ifdef O_CLOEXEC 99#ifdef O_CLOEXEC
99 int cloexec = 0; 100 int cloexec = 0;
@@ -185,13 +186,29 @@ local gzFile gz_open(path, fd, mode)
185 } 186 }
186 187
187 /* save the path name for error messages */ 188 /* save the path name for error messages */
188# define WPATH "<widepath>" 189#ifdef _WIN32
189 state->path = malloc(strlen(fd == -2 ? WPATH : path) + 1); 190 if (fd == -2) {
191 len = wcstombs(NULL, path, 0);
192 if (len == (size_t)-1)
193 len = 0;
194 }
195 else
196#endif
197 len = strlen(path);
198 state->path = malloc(len + 1);
190 if (state->path == NULL) { 199 if (state->path == NULL) {
191 free(state); 200 free(state);
192 return NULL; 201 return NULL;
193 } 202 }
194 strcpy(state->path, fd == -2 ? WPATH : path); 203#ifdef _WIN32
204 if (fd == -2)
205 if (len)
206 wcstombs(state->path, path, len + 1);
207 else
208 *(state->path) = 0;
209 else
210#endif
211 strcpy(state->path, path);
195 212
196 /* compute the flags for open() */ 213 /* compute the flags for open() */
197 oflag = 214 oflag =