mirror of
https://gitlab.freedesktop.org/plymouth/plymouth.git
synced 2026-05-08 12:28:12 +02:00
add new wrapper around the pipe() syscall
This commit is contained in:
parent
1c9d5b99f2
commit
9ec699290d
2 changed files with 42 additions and 0 deletions
35
src/ply-utils.c
Normal file
35
src/ply-utils.c
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
@ -22,6 +22,8 @@
|
||||||
#ifndef PLY_UTILS_H
|
#ifndef PLY_UTILS_H
|
||||||
#define PLY_UTILS_H
|
#define PLY_UTILS_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifndef MIN
|
#ifndef MIN
|
||||||
#define MIN(a,b) ((a) <= (b)? (a) : (b))
|
#define MIN(a,b) ((a) <= (b)? (a) : (b))
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -34,5 +36,10 @@
|
||||||
#define CLAMP(a,b,c) (MIN (MAX ((a), (b)), (c)))
|
#define CLAMP(a,b,c) (MIN (MAX ((a), (b)), (c)))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef PLY_HIDE_FUNCTION_DECLARATIONS
|
||||||
|
bool ply_open_unidirectional_pipe (int *sender_fd,
|
||||||
|
int *receiver_fd);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* PLY_UTILS_H */
|
#endif /* PLY_UTILS_H */
|
||||||
/* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */
|
/* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue