From 9ec699290d847e9c6e69bb982a3f98913db91747 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Mon, 14 May 2007 15:00:50 -0400 Subject: [PATCH] add new wrapper around the pipe() syscall --- src/ply-utils.c | 35 +++++++++++++++++++++++++++++++++++ src/ply-utils.h | 7 +++++++ 2 files changed, 42 insertions(+) create mode 100644 src/ply-utils.c 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: */ -- 2.47.3