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 /gzlib.c | |
parent | 04afd39fcc753e2f1369cb471cb6592ea5946546 (diff) | |
download | zlib-a5d803b7efde22b8d26a8d8e3044c13281a3ea9a.tar.gz |
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.
Diffstat (limited to 'gzlib.c')
-rw-r--r-- | gzlib.c | 23 |
1 files changed, 20 insertions, 3 deletions
@@ -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 = |