summaryrefslogtreecommitdiffstats
path: root/osdep
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-10-26 01:18:55 +0200
committerwm4 <wm4@nowhere>2014-10-26 01:40:36 +0200
commit6f88bc77617dbf8a919830ae070e5ca926755587 (patch)
treee2922d05c7bc3cc22f2bed8bad587f7bfa8d2311 /osdep
parent38546d5a998e546b976fc5b8c0525cead670e9f3 (diff)
downloadmpv-6f88bc77617dbf8a919830ae070e5ca926755587.tar.bz2
mpv-6f88bc77617dbf8a919830ae070e5ca926755587.tar.xz
osdep: add helper for creating a sane pipe()
Or in other words, a pipe that has the CLOEXEC flag set. Needed since Linux' pipe2() is not in POSIX yet.
Diffstat (limited to 'osdep')
-rw-r--r--osdep/io.c24
-rw-r--r--osdep/io.h1
2 files changed, 21 insertions, 4 deletions
diff --git a/osdep/io.c b/osdep/io.c
index 37ea37f058..00715288a9 100644
--- a/osdep/io.c
+++ b/osdep/io.c
@@ -43,22 +43,38 @@ bool mp_set_cloexec(int fd)
}
#ifdef __MINGW32__
-int mp_make_wakeup_pipe(int pipes[2])
+int mp_make_cloexec_pipe(int pipes[2])
{
pipes[0] = pipes[1] = -1;
return -1;
}
#else
-// create a pipe, and set it to non-blocking (and also set FD_CLOEXEC)
-int mp_make_wakeup_pipe(int pipes[2])
+int mp_make_cloexec_pipe(int pipes[2])
{
if (pipe(pipes) != 0) {
pipes[0] = pipes[1] = -1;
return -1;
}
- for (int i = 0; i < 2; i++) {
+ for (int i = 0; i < 2; i++)
mp_set_cloexec(pipes[i]);
+ return 0;
+}
+#endif
+
+#ifdef __MINGW32__
+int mp_make_wakeup_pipe(int pipes[2])
+{
+ mp_make_cloexec_pipe(pipes);
+}
+#else
+// create a pipe, and set it to non-blocking (and also set FD_CLOEXEC)
+int mp_make_wakeup_pipe(int pipes[2])
+{
+ if (mp_make_cloexec_pipe(pipes) < 0)
+ return -1;
+
+ for (int i = 0; i < 2; i++) {
int val = fcntl(pipes[i], F_GETFL) | O_NONBLOCK;
fcntl(pipes[i], F_SETFL, val);
}
diff --git a/osdep/io.h b/osdep/io.h
index ac1a0f90fa..c3fc0cf9cb 100644
--- a/osdep/io.h
+++ b/osdep/io.h
@@ -45,6 +45,7 @@
#endif
bool mp_set_cloexec(int fd);
+int mp_make_cloexec_pipe(int pipes[2]);
int mp_make_wakeup_pipe(int pipes[2]);
#ifdef _WIN32