aboutsummaryrefslogtreecommitdiff
path: root/gzlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'gzlib.c')
-rw-r--r--gzlib.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/gzlib.c b/gzlib.c
index 983153c..05a9ae5 100644
--- a/gzlib.c
+++ b/gzlib.c
@@ -52,7 +52,8 @@ char ZLIB_INTERNAL *gz_strwinerror(DWORD error) {
52 msgbuf[chars] = 0; 52 msgbuf[chars] = 0;
53 } 53 }
54 54
55 wcstombs(buf, msgbuf, chars + 1); 55 z_size_t len;
56 wcstombs_s(&len, buf, sizeof(buf), msgbuf, chars + 1);
56 LocalFree(msgbuf); 57 LocalFree(msgbuf);
57 } 58 }
58 else { 59 else {
@@ -180,8 +181,7 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
180 /* save the path name for error messages */ 181 /* save the path name for error messages */
181#ifdef WIDECHAR 182#ifdef WIDECHAR
182 if (fd == -2) { 183 if (fd == -2) {
183 len = wcstombs(NULL, path, 0); 184 if (wcstombs_s(&len, NULL, 0, path, 0) != 0)
184 if (len == (z_size_t)-1)
185 len = 0; 185 len = 0;
186 } 186 }
187 else 187 else
@@ -195,7 +195,7 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
195#ifdef WIDECHAR 195#ifdef WIDECHAR
196 if (fd == -2) 196 if (fd == -2)
197 if (len) 197 if (len)
198 wcstombs(state->path, path, len + 1); 198 wcstombs_s(&len, state->path, len + 1, path, len + 1);
199 else 199 else
200 *(state->path) = 0; 200 *(state->path) = 0;
201 else 201 else
@@ -228,11 +228,14 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
228 O_APPEND))); 228 O_APPEND)));
229 229
230 /* open the file with the appropriate flags (or just use fd) */ 230 /* open the file with the appropriate flags (or just use fd) */
231 state->fd = fd > -1 ? fd : ( 231 if (fd == -1)
232 state->fd = open((const char *)path, oflag, 0666);
232#ifdef WIDECHAR 233#ifdef WIDECHAR
233 fd == -2 ? _wopen(path, oflag, 0666) : 234 else if (fd == -2)
235 _wsopen_s(&state->fd, path, oflag, _SH_DENYNO, _S_IREAD | _S_IWRITE);
234#endif 236#endif
235 open((const char *)path, oflag, 0666)); 237 else
238 state->fd = fd;
236 if (state->fd == -1) { 239 if (state->fd == -1) {
237 free(state->path); 240 free(state->path);
238 free(state); 241 free(state);