]> git.ozlabs.org Git - ccan/blob - ccan/pipecmd/pipecmd.h
5bbaefc01234699e23ab719d2495161f9ae1b935
[ccan] / ccan / pipecmd / pipecmd.h
1 /* CC0 license (public domain) - see LICENSE file for details */
2 #ifndef CCAN_PIPECMD_H
3 #define CCAN_PIPECMD_H
4 #include "config.h"
5 #include <sys/types.h>
6 #include <sys/wait.h>
7 #include <stdarg.h>
8
9 /**
10  * pipecmd - run a command, optionally connect pipes.
11  * @infd: input fd to write to child (if non-NULL)
12  * @outfd: output fd to read from child (if non-NULL)
13  * @errfd: error-output fd to read from child (if non-NULL)
14  * @cmd...: NULL-terminate list of command and arguments.
15  *
16  * If @infd is NULL, the child's input is (read-only) /dev/null.
17  * If @outfd is NULL, the child's output is (write-only) /dev/null.
18  * If @errfd is NULL, the child's stderr is (write-only) /dev/null.
19  *
20  * If @errfd == @outfd (and non-NULL) they will be shared.
21  * If @infd, @outfd or @errfd is &pipecmd_preserve, it is unchanged.
22  *
23  * The return value is the pid of the child, or -1.
24  */
25 pid_t pipecmd(int *infd, int *outfd, int *errfd, const char *cmd, ...);
26
27 /**
28  * pipecmdv - run a command, optionally connect pipes (stdarg version)
29  * @infd: input fd to write to child (if non-NULL)
30  * @outfd: output fd to read from child (if non-NULL)
31  * @errfd: error-output fd to read from child (if non-NULL)
32  * @cmd: command to run.
33  * @ap: argument list for arguments.
34  */
35 pid_t pipecmdv(int *infd, int *outfd, int *errfd, const char *cmd, va_list ap);
36
37 /**
38  * pipecmdarr - run a command, optionally connect pipes (char arry version)
39  * @infd: input fd to write to child (if non-NULL)
40  * @outfd: output fd to read from child (if non-NULL)
41  * @errfd: error-output fd to read from child (if non-NULL)
42  * @arr: NULL-terminated array for arguments (first is program to run).
43  */
44 pid_t pipecmdarr(int *infd, int *outfd, int *errfd, char *const *arr);
45
46 /**
47  * pipecmd_preserve - special value for fds to indicate it is unchanged
48  */
49 extern int pipecmd_preserve;
50
51 #endif /* CCAN_PIPECMD_H */