提交 755c41dc 编写于 作者: M Mark Adler

Add "x" (O_EXCL) and "e" (O_CLOEXEC) modes support to gzopen().

上级 53bfe01c
...@@ -94,6 +94,7 @@ local gzFile gz_open(path, fd, mode) ...@@ -94,6 +94,7 @@ local gzFile gz_open(path, fd, mode)
const char *mode; const char *mode;
{ {
gz_statep state; gz_statep state;
int cloexec = 0, exclusive = 0;
/* check input */ /* check input */
if (path == NULL) if (path == NULL)
...@@ -133,6 +134,12 @@ local gzFile gz_open(path, fd, mode) ...@@ -133,6 +134,12 @@ local gzFile gz_open(path, fd, mode)
return NULL; return NULL;
case 'b': /* ignore -- will request binary anyway */ case 'b': /* ignore -- will request binary anyway */
break; break;
case 'e':
cloexec = 1;
break;
case 'x':
exclusive = 1;
break;
case 'f': case 'f':
state->strategy = Z_FILTERED; state->strategy = Z_FILTERED;
break; break;
...@@ -183,10 +190,13 @@ local gzFile gz_open(path, fd, mode) ...@@ -183,10 +190,13 @@ local gzFile gz_open(path, fd, mode)
#endif #endif
#ifdef O_BINARY #ifdef O_BINARY
O_BINARY | O_BINARY |
#endif
#ifdef O_CLOEXEC
(cloexec ? O_CLOEXEC : 0) |
#endif #endif
(state->mode == GZ_READ ? (state->mode == GZ_READ ?
O_RDONLY : O_RDONLY :
(O_WRONLY | O_CREAT | ( (O_WRONLY | O_CREAT | (exclusive ? O_EXCL : 0) | (
state->mode == GZ_WRITE ? state->mode == GZ_WRITE ?
O_TRUNC : O_TRUNC :
O_APPEND))), O_APPEND))),
......
...@@ -1217,7 +1217,10 @@ ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); ...@@ -1217,7 +1217,10 @@ ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
"a" can be used instead of "w" to request that the gzip stream that will "a" can be used instead of "w" to request that the gzip stream that will
be written be appended to the file. "+" will result in an error, since be written be appended to the file. "+" will result in an error, since
reading and writing to the same gzip file is not supported. reading and writing to the same gzip file is not supported. The addition of
"x" when writing will create the file exclusively, which fails if the file
already exists. On systems that support it, the addition of "e" when
reading or writing will set the flag to close the file on an execve() call.
These functions, as well as gzip, will read and decode a sequence of gzip These functions, as well as gzip, will read and decode a sequence of gzip
streams in a file. The append function of gzopen() can be used to create streams in a file. The append function of gzopen() can be used to create
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册