diff options
| author | Mark Adler <madler@alumni.caltech.edu> | 2012-03-18 14:52:31 -0700 |
|---|---|---|
| committer | Mark Adler <madler@alumni.caltech.edu> | 2012-03-18 14:52:31 -0700 |
| commit | a5d803b7efde22b8d26a8d8e3044c13281a3ea9a (patch) | |
| tree | 9e54d63be9bafdc986e09be6f71be9331a9779dd | |
| parent | 04afd39fcc753e2f1369cb471cb6592ea5946546 (diff) | |
| download | zlib-a5d803b7efde22b8d26a8d8e3044c13281a3ea9a.tar.gz zlib-a5d803b7efde22b8d26a8d8e3044c13281a3ea9a.tar.bz2 zlib-a5d803b7efde22b8d26a8d8e3044c13281a3ea9a.zip | |
Attempt to convert the wchar_t path in gzopen_w() for errors.
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.
| -rw-r--r-- | gzlib.c | 23 |
1 files changed, 20 insertions, 3 deletions
| @@ -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 = |
