From: Ray Strode Date: Mon, 14 May 2007 19:00:50 +0000 (-0400) Subject: add new wrapper around the pipe() syscall X-Git-Tag: 0.1.0~304 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ec69929;p=thirdparty%2Fplymouth.git add new wrapper around the pipe() syscall --- diff --git a/src/ply-utils.c b/src/ply-utils.c new file mode 100644 index 00000000..81268b43 --- /dev/null +++ b/src/ply-utils.c @@ -0,0 +1,35 @@ +#include + +#include "ply-utils.h" + +bool +ply_open_unidirectional_pipe (int *sender_fd, + int *receiver_fd) +{ + init pipe_fds[2]; + + assert (sender_fd != NULL); + assert (receiver_fd != NULL); + + if (pipe (pipe_fds) < 0) + return false; + + if (fcntl (pipe_fds[0], F_SETFD, O_NONBLOCK | FD_CLOEXEC) < 0) + { + close (pipe_fds[0]); + close (pipe_fds[1]); + return false; + } + + if (fcntl (pipe_fds[1], F_SETFD, O_NONBLOCK | FD_CLOEXEC) < 0) + { + close (pipe_fds[0]); + close (pipe_fds[1]); + return false; + } + + *sender_fd = pipe_fds[1]; + *receiver_fd = pipe_fds[0]; + + return true; +} diff --git a/src/ply-utils.h b/src/ply-utils.h index ca821686..3d7925ac 100644 --- a/src/ply-utils.h +++ b/src/ply-utils.h @@ -22,6 +22,8 @@ #ifndef PLY_UTILS_H #define PLY_UTILS_H +#include + #ifndef MIN #define MIN(a,b) ((a) <= (b)? (a) : (b)) #endif @@ -34,5 +36,10 @@ #define CLAMP(a,b,c) (MIN (MAX ((a), (b)), (c))) #endif +#ifndef PLY_HIDE_FUNCTION_DECLARATIONS +bool ply_open_unidirectional_pipe (int *sender_fd, + int *receiver_fd); +#endif + #endif /* PLY_UTILS_H */ /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */