1
mirror of https://github.com/mpv-player/mpv synced 2024-07-31 16:29:58 +02:00

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.
This commit is contained in:
wm4 2014-10-26 01:18:55 +02:00
parent 38546d5a99
commit 6f88bc7761
2 changed files with 21 additions and 4 deletions

View File

@ -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);
}

View File

@ -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