diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2012-03-16 20:53:09 -0700 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2012-03-16 20:53:09 -0700 |
commit | dbe0bed739c26a2c36319794108cb87ad77c5469 (patch) | |
tree | d09f1697ce762b88f7a2d1cff1969fb9ecee09d3 /gzlib.c | |
parent | a3881cc745729cde05d921b3750e2d56889b5d26 (diff) | |
download | zlib-dbe0bed739c26a2c36319794108cb87ad77c5469.tar.gz zlib-dbe0bed739c26a2c36319794108cb87ad77c5469.tar.bz2 zlib-dbe0bed739c26a2c36319794108cb87ad77c5469.zip |
Add gzopen_w() in Windows for wide character path names.
Diffstat (limited to 'gzlib.c')
-rw-r--r-- | gzlib.c | 48 |
1 files changed, 32 insertions, 16 deletions
@@ -17,7 +17,7 @@ | |||
17 | 17 | ||
18 | /* Local functions */ | 18 | /* Local functions */ |
19 | local void gz_reset OF((gz_statep)); | 19 | local void gz_reset OF((gz_statep)); |
20 | local gzFile gz_open OF((const char *, int, const char *)); | 20 | local gzFile gz_open OF((const void *, int, const char *)); |
21 | 21 | ||
22 | #if defined UNDER_CE | 22 | #if defined UNDER_CE |
23 | 23 | ||
@@ -89,11 +89,12 @@ local void gz_reset(state) | |||
89 | 89 | ||
90 | /* Open a gzip file either by name or file descriptor. */ | 90 | /* Open a gzip file either by name or file descriptor. */ |
91 | local gzFile gz_open(path, fd, mode) | 91 | local gzFile gz_open(path, fd, mode) |
92 | const char *path; | 92 | const void *path; |
93 | int fd; | 93 | int fd; |
94 | const char *mode; | 94 | const char *mode; |
95 | { | 95 | { |
96 | gz_statep state; | 96 | gz_statep state; |
97 | int oflag; | ||
97 | #ifdef O_CLOEXEC | 98 | #ifdef O_CLOEXEC |
98 | int cloexec = 0; | 99 | int cloexec = 0; |
99 | #endif | 100 | #endif |
@@ -191,28 +192,33 @@ local gzFile gz_open(path, fd, mode) | |||
191 | } | 192 | } |
192 | strcpy(state->path, path); | 193 | strcpy(state->path, path); |
193 | 194 | ||
194 | /* open the file with the appropriate mode (or just use fd) */ | 195 | /* compute the flags for open() */ |
195 | state->fd = fd != -1 ? fd : | 196 | oflag = |
196 | open(path, | ||
197 | #ifdef O_LARGEFILE | 197 | #ifdef O_LARGEFILE |
198 | O_LARGEFILE | | 198 | O_LARGEFILE | |
199 | #endif | 199 | #endif |
200 | #ifdef O_BINARY | 200 | #ifdef O_BINARY |
201 | O_BINARY | | 201 | O_BINARY | |
202 | #endif | 202 | #endif |
203 | #ifdef O_CLOEXEC | 203 | #ifdef O_CLOEXEC |
204 | (cloexec ? O_CLOEXEC : 0) | | 204 | (cloexec ? O_CLOEXEC : 0) | |
205 | #endif | 205 | #endif |
206 | (state->mode == GZ_READ ? | 206 | (state->mode == GZ_READ ? |
207 | O_RDONLY : | 207 | O_RDONLY : |
208 | (O_WRONLY | O_CREAT | | 208 | (O_WRONLY | O_CREAT | |
209 | #ifdef O_EXCL | 209 | #ifdef O_EXCL |
210 | (exclusive ? O_EXCL : 0) | | 210 | (exclusive ? O_EXCL : 0) | |
211 | #endif | ||
212 | (state->mode == GZ_WRITE ? | ||
213 | O_TRUNC : | ||
214 | O_APPEND))); | ||
215 | |||
216 | /* open the file with the appropriate flags (or just use fd) */ | ||
217 | state->fd = fd > -1 ? fd : ( | ||
218 | #ifdef _WIN32 | ||
219 | fd == -2 ? _wopen(path, oflag, 0666) : | ||
211 | #endif | 220 | #endif |
212 | (state->mode == GZ_WRITE ? | 221 | open(path, oflag, 0666)); |
213 | O_TRUNC : | ||
214 | O_APPEND))), | ||
215 | 0666); | ||
216 | if (state->fd == -1) { | 222 | if (state->fd == -1) { |
217 | free(state->path); | 223 | free(state->path); |
218 | free(state); | 224 | free(state); |
@@ -267,6 +273,16 @@ gzFile ZEXPORT gzdopen(fd, mode) | |||
267 | } | 273 | } |
268 | 274 | ||
269 | /* -- see zlib.h -- */ | 275 | /* -- see zlib.h -- */ |
276 | #ifdef _WIN32 | ||
277 | gzFile ZEXPORT gzopen_w(path, mode) | ||
278 | const w_char *path; | ||
279 | const char *mode; | ||
280 | { | ||
281 | return gz_open(path, -2, mode); | ||
282 | } | ||
283 | #endif | ||
284 | |||
285 | /* -- see zlib.h -- */ | ||
270 | int ZEXPORT gzbuffer(file, size) | 286 | int ZEXPORT gzbuffer(file, size) |
271 | gzFile file; | 287 | gzFile file; |
272 | unsigned size; | 288 | unsigned size; |