diff options
| author | Mark Adler <madler@alumni.caltech.edu> | 2012-03-03 10:24:44 -0800 |
|---|---|---|
| committer | Mark Adler <madler@alumni.caltech.edu> | 2012-03-03 10:27:57 -0800 |
| commit | 755c41dc4bcde575ae654065921206ab4efec962 (patch) | |
| tree | ae3799ffcd9a6ed0d0206d7dae912ad5fb59fd15 | |
| parent | 53bfe01cea647ef6f6b86edbc51d0fad4640e4a6 (diff) | |
| download | zlib-755c41dc4bcde575ae654065921206ab4efec962.tar.gz zlib-755c41dc4bcde575ae654065921206ab4efec962.tar.bz2 zlib-755c41dc4bcde575ae654065921206ab4efec962.zip | |
Add "x" (O_EXCL) and "e" (O_CLOEXEC) modes support to gzopen().
| -rw-r--r-- | gzlib.c | 12 | ||||
| -rw-r--r-- | zlib.h | 5 |
2 files changed, 15 insertions, 2 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 | int cloexec = 0, exclusive = 0; | ||
| 97 | 98 | ||
| 98 | /* check input */ | 99 | /* check input */ |
| 99 | if (path == NULL) | 100 | if (path == NULL) |
| @@ -133,6 +134,12 @@ local gzFile gz_open(path, fd, mode) | |||
| 133 | return NULL; | 134 | return NULL; |
| 134 | case 'b': /* ignore -- will request binary anyway */ | 135 | case 'b': /* ignore -- will request binary anyway */ |
| 135 | break; | 136 | break; |
| 137 | case 'e': | ||
| 138 | cloexec = 1; | ||
| 139 | break; | ||
| 140 | case 'x': | ||
| 141 | exclusive = 1; | ||
| 142 | break; | ||
| 136 | case 'f': | 143 | case 'f': |
| 137 | state->strategy = Z_FILTERED; | 144 | state->strategy = Z_FILTERED; |
| 138 | break; | 145 | break; |
| @@ -184,9 +191,12 @@ local gzFile gz_open(path, fd, mode) | |||
| 184 | #ifdef O_BINARY | 191 | #ifdef O_BINARY |
| 185 | O_BINARY | | 192 | O_BINARY | |
| 186 | #endif | 193 | #endif |
| 194 | #ifdef O_CLOEXEC | ||
| 195 | (cloexec ? O_CLOEXEC : 0) | | ||
| 196 | #endif | ||
| 187 | (state->mode == GZ_READ ? | 197 | (state->mode == GZ_READ ? |
| 188 | O_RDONLY : | 198 | O_RDONLY : |
| 189 | (O_WRONLY | O_CREAT | ( | 199 | (O_WRONLY | O_CREAT | (exclusive ? O_EXCL : 0) | ( |
| 190 | state->mode == GZ_WRITE ? | 200 | state->mode == GZ_WRITE ? |
| 191 | O_TRUNC : | 201 | O_TRUNC : |
| 192 | O_APPEND))), | 202 | O_APPEND))), |
| @@ -1217,7 +1217,10 @@ ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); | |||
| 1217 | 1217 | ||
| 1218 | "a" can be used instead of "w" to request that the gzip stream that will | 1218 | "a" can be used instead of "w" to request that the gzip stream that will |
| 1219 | be written be appended to the file. "+" will result in an error, since | 1219 | be written be appended to the file. "+" will result in an error, since |
| 1220 | reading and writing to the same gzip file is not supported. | 1220 | reading and writing to the same gzip file is not supported. The addition of |
| 1221 | "x" when writing will create the file exclusively, which fails if the file | ||
| 1222 | already exists. On systems that support it, the addition of "e" when | ||
| 1223 | reading or writing will set the flag to close the file on an execve() call. | ||
| 1221 | 1224 | ||
| 1222 | These functions, as well as gzip, will read and decode a sequence of gzip | 1225 | These functions, as well as gzip, will read and decode a sequence of gzip |
| 1223 | streams in a file. The append function of gzopen() can be used to create | 1226 | streams in a file. The append function of gzopen() can be used to create |
