diff options
| author | Mark Adler <git@madler.net> | 2025-05-25 19:01:36 -0700 |
|---|---|---|
| committer | Mark Adler <git@madler.net> | 2025-12-08 03:52:25 -0800 |
| commit | 81cc0bebedd935daeb81b0b6e475d8786b51af3d (patch) | |
| tree | dbd05e0ccc349d0ab90d20374716fb400d383e68 /gzlib.c | |
| parent | 598130fd078f7b712498d348cf94b4b9806c4435 (diff) | |
| download | zlib-81cc0bebedd935daeb81b0b6e475d8786b51af3d.tar.gz zlib-81cc0bebedd935daeb81b0b6e475d8786b51af3d.tar.bz2 zlib-81cc0bebedd935daeb81b0b6e475d8786b51af3d.zip | |
Support non-blocking devices in the gz* routines.
Diffstat (limited to 'gzlib.c')
| -rw-r--r-- | gzlib.c | 34 |
1 files changed, 22 insertions, 12 deletions
| @@ -52,7 +52,7 @@ 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); // assumes buf is big enough | 55 | wcstombs(buf, msgbuf, chars + 1); /* assumes buf is big enough */ |
| 56 | LocalFree(msgbuf); | 56 | LocalFree(msgbuf); |
| 57 | } | 57 | } |
| 58 | else { | 58 | else { |
| @@ -76,6 +76,7 @@ local void gz_reset(gz_statep state) { | |||
| 76 | } | 76 | } |
| 77 | else /* for writing ... */ | 77 | else /* for writing ... */ |
| 78 | state->reset = 0; /* no deflateReset pending */ | 78 | state->reset = 0; /* no deflateReset pending */ |
| 79 | state->again = 0; /* no stalled i/o yet */ | ||
| 79 | state->skip = 0; /* no seek request pending */ | 80 | state->skip = 0; /* no seek request pending */ |
| 80 | gz_error(state, Z_OK, NULL); /* clear error */ | 81 | gz_error(state, Z_OK, NULL); /* clear error */ |
| 81 | state->x.pos = 0; /* no uncompressed data yet */ | 82 | state->x.pos = 0; /* no uncompressed data yet */ |
| @@ -86,10 +87,7 @@ local void gz_reset(gz_statep state) { | |||
| 86 | local gzFile gz_open(const void *path, int fd, const char *mode) { | 87 | local gzFile gz_open(const void *path, int fd, const char *mode) { |
| 87 | gz_statep state; | 88 | gz_statep state; |
| 88 | z_size_t len; | 89 | z_size_t len; |
| 89 | int oflag; | 90 | int oflag = 0; |
| 90 | #ifdef O_CLOEXEC | ||
| 91 | int cloexec = 0; | ||
| 92 | #endif | ||
| 93 | #ifdef O_EXCL | 91 | #ifdef O_EXCL |
| 94 | int exclusive = 0; | 92 | int exclusive = 0; |
| 95 | #endif | 93 | #endif |
| @@ -135,7 +133,7 @@ local gzFile gz_open(const void *path, int fd, const char *mode) { | |||
| 135 | break; | 133 | break; |
| 136 | #ifdef O_CLOEXEC | 134 | #ifdef O_CLOEXEC |
| 137 | case 'e': | 135 | case 'e': |
| 138 | cloexec = 1; | 136 | oflag |= O_CLOEXEC; |
| 139 | break; | 137 | break; |
| 140 | #endif | 138 | #endif |
| 141 | #ifdef O_EXCL | 139 | #ifdef O_EXCL |
| @@ -158,6 +156,11 @@ local gzFile gz_open(const void *path, int fd, const char *mode) { | |||
| 158 | case 'G': | 156 | case 'G': |
| 159 | state->direct = -1; | 157 | state->direct = -1; |
| 160 | break; | 158 | break; |
| 159 | #ifdef O_NONBLOCK | ||
| 160 | case 'N': | ||
| 161 | oflag |= O_NONBLOCK; | ||
| 162 | break; | ||
| 163 | #endif | ||
| 161 | case 'T': | 164 | case 'T': |
| 162 | state->direct = 1; | 165 | state->direct = 1; |
| 163 | break; | 166 | break; |
| @@ -223,16 +226,13 @@ local gzFile gz_open(const void *path, int fd, const char *mode) { | |||
| 223 | } | 226 | } |
| 224 | 227 | ||
| 225 | /* compute the flags for open() */ | 228 | /* compute the flags for open() */ |
| 226 | oflag = | 229 | oflag |= |
| 227 | #ifdef O_LARGEFILE | 230 | #ifdef O_LARGEFILE |
| 228 | O_LARGEFILE | | 231 | O_LARGEFILE | |
| 229 | #endif | 232 | #endif |
| 230 | #ifdef O_BINARY | 233 | #ifdef O_BINARY |
| 231 | O_BINARY | | 234 | O_BINARY | |
| 232 | #endif | 235 | #endif |
| 233 | #ifdef O_CLOEXEC | ||
| 234 | (cloexec ? O_CLOEXEC : 0) | | ||
| 235 | #endif | ||
| 236 | (state->mode == GZ_READ ? | 236 | (state->mode == GZ_READ ? |
| 237 | O_RDONLY : | 237 | O_RDONLY : |
| 238 | (O_WRONLY | O_CREAT | | 238 | (O_WRONLY | O_CREAT | |
| @@ -250,8 +250,17 @@ local gzFile gz_open(const void *path, int fd, const char *mode) { | |||
| 250 | else if (fd == -2) | 250 | else if (fd == -2) |
| 251 | state->fd = _wopen(path, oflag, _S_IREAD | _S_IWRITE); | 251 | state->fd = _wopen(path, oflag, _S_IREAD | _S_IWRITE); |
| 252 | #endif | 252 | #endif |
| 253 | else | 253 | else { |
| 254 | #ifdef O_NONBLOCK | ||
| 255 | if (oflag & O_NONBLOCK) | ||
| 256 | fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); | ||
| 257 | #endif | ||
| 258 | #ifdef O_CLOEXEC | ||
| 259 | if (oflag & O_CLOEXEC) | ||
| 260 | fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | O_CLOEXEC); | ||
| 261 | #endif | ||
| 254 | state->fd = fd; | 262 | state->fd = fd; |
| 263 | } | ||
| 255 | if (state->fd == -1) { | 264 | if (state->fd == -1) { |
| 256 | free(state->path); | 265 | free(state->path); |
| 257 | free(state); | 266 | free(state); |
| @@ -552,7 +561,7 @@ void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg) { | |||
| 552 | } | 561 | } |
| 553 | 562 | ||
| 554 | /* if fatal, set state->x.have to 0 so that the gzgetc() macro fails */ | 563 | /* if fatal, set state->x.have to 0 so that the gzgetc() macro fails */ |
| 555 | if (err != Z_OK && err != Z_BUF_ERROR) | 564 | if (err != Z_OK && err != Z_BUF_ERROR && !state->again) |
| 556 | state->x.have = 0; | 565 | state->x.have = 0; |
| 557 | 566 | ||
| 558 | /* set error code, and if no message, then done */ | 567 | /* set error code, and if no message, then done */ |
| @@ -589,6 +598,7 @@ unsigned ZLIB_INTERNAL gz_intmax(void) { | |||
| 589 | return INT_MAX; | 598 | return INT_MAX; |
| 590 | #else | 599 | #else |
| 591 | unsigned p = 1, q; | 600 | unsigned p = 1, q; |
| 601 | |||
| 592 | do { | 602 | do { |
| 593 | q = p; | 603 | q = p; |
| 594 | p <<= 1; | 604 | p <<= 1; |
