From 755c41dc4bcde575ae654065921206ab4efec962 Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Sat, 3 Mar 2012 10:24:44 -0800 Subject: Add "x" (O_EXCL) and "e" (O_CLOEXEC) modes support to gzopen(). --- gzlib.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'gzlib.c') diff --git a/gzlib.c b/gzlib.c index 7aedab8..fec7fbf 100644 --- a/gzlib.c +++ b/gzlib.c @@ -94,6 +94,7 @@ local gzFile gz_open(path, fd, mode) const char *mode; { gz_statep state; + int cloexec = 0, exclusive = 0; /* check input */ if (path == NULL) @@ -133,6 +134,12 @@ local gzFile gz_open(path, fd, mode) return NULL; case 'b': /* ignore -- will request binary anyway */ break; + case 'e': + cloexec = 1; + break; + case 'x': + exclusive = 1; + break; case 'f': state->strategy = Z_FILTERED; break; @@ -183,10 +190,13 @@ local gzFile gz_open(path, fd, mode) #endif #ifdef O_BINARY O_BINARY | +#endif +#ifdef O_CLOEXEC + (cloexec ? O_CLOEXEC : 0) | #endif (state->mode == GZ_READ ? O_RDONLY : - (O_WRONLY | O_CREAT | ( + (O_WRONLY | O_CREAT | (exclusive ? O_EXCL : 0) | ( state->mode == GZ_WRITE ? O_TRUNC : O_APPEND))), -- cgit v1.2.3-55-g6feb