aboutsummaryrefslogtreecommitdiffstats
path: root/src/fd_util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fd_util.c')
-rw-r--r--src/fd_util.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/fd_util.c b/src/fd_util.c
index 8f142e34a..f78b8ed8b 100644
--- a/src/fd_util.c
+++ b/src/fd_util.c
@@ -101,7 +101,7 @@ fd_set_nonblock(int fd)
}
int
-open_cloexec(const char *path_fs, int flags)
+open_cloexec(const char *path_fs, int flags, int mode)
{
int fd;
@@ -113,30 +113,34 @@ open_cloexec(const char *path_fs, int flags)
flags |= O_NOCTTY;
#endif
- fd = open(path_fs, flags, 0666);
+ fd = open(path_fs, flags, mode);
fd_set_cloexec(fd, true);
return fd;
}
int
-creat_cloexec(const char *path_fs, int mode)
+pipe_cloexec(int fd[2])
{
- int flags = O_CREAT|O_WRONLY|O_TRUNC;
- int fd;
-
-#ifdef O_CLOEXEC
- flags |= O_CLOEXEC;
-#endif
+#ifdef WIN32
+ return _pipe(event_pipe, 512, _O_BINARY);
+#else
+ int ret;
-#ifdef O_NOCTTY
- flags |= O_NOCTTY;
+#ifdef HAVE_PIPE2
+ ret = pipe2(fd, O_CLOEXEC);
+ if (ret >= 0 || errno != ENOSYS)
+ return ret;
#endif
- fd = open(path_fs, flags, mode);
- fd_set_cloexec(fd, true);
+ ret = pipe(fd);
+ if (ret >= 0) {
+ fd_set_cloexec(fd[0], true);
+ fd_set_cloexec(fd[1], true);
+ }
- return fd;
+ return ret;
+#endif
}
int
@@ -158,10 +162,8 @@ pipe_cloexec_nonblock(int fd[2])
fd_set_cloexec(fd[0], true);
fd_set_cloexec(fd[1], true);
-#ifndef WIN32
fd_set_nonblock(fd[0]);
fd_set_nonblock(fd[1]);
-#endif
}
return ret;