diff options
Diffstat (limited to 'osdep')
-rw-r--r-- | osdep/io.c | 25 | ||||
-rw-r--r-- | osdep/io.h | 1 |
2 files changed, 26 insertions, 0 deletions
diff --git a/osdep/io.c b/osdep/io.c index 807ec0a0d0..27235e092c 100644 --- a/osdep/io.c +++ b/osdep/io.c @@ -19,6 +19,7 @@ */ #include <unistd.h> +#include <errno.h> #include "talloc.h" @@ -41,6 +42,30 @@ bool mp_set_cloexec(int fd) return true; } +#ifdef __MINGW32__ +int mp_make_wakeup_pipe(int pipes[2]) +{ + pipes[0] = pipes[1] = -1; + return -ENOSYS; +} +#else +// create a pipe, and set it to non-blocking (and also set FD_CLOEXEC) +int mp_make_wakeup_pipe(int pipes[2]) +{ + if (pipe(pipes) != 0) { + pipes[0] = pipes[1] = -1; + return -errno; + } + + for (int i = 0; i < 2; i++) { + mp_set_cloexec(pipes[i]); + int val = fcntl(pipes[i], F_GETFL) | O_NONBLOCK; + fcntl(pipes[i], F_SETFL, val); + } + return 0; +} +#endif + #ifdef _WIN32 #include <windows.h> diff --git a/osdep/io.h b/osdep/io.h index 53097a1b78..306e2ac6ec 100644 --- a/osdep/io.h +++ b/osdep/io.h @@ -44,6 +44,7 @@ #endif bool mp_set_cloexec(int fd); +int mp_make_wakeup_pipe(int pipes[2]); #ifdef _WIN32 #include <wchar.h> |