pipecmd.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. * pipecmd - run a command, optionally connect pipes.
  10. * @infd: input fd to write to child (if non-NULL)
  11. * @outfd: output fd to read from child (if non-NULL)
  12. * @errfd: error-output fd to read from child (if non-NULL)
  13. * @cmd...: NULL-terminate list of command and arguments.
  14. *
  15. * If @infd is NULL, the child's input is (read-only) /dev/null.
  16. * If @outfd is NULL, the child's output is (write-only) /dev/null.
  17. * If @errfd is NULL, the child's stderr is (write-only) /dev/null.
  18. *
  19. * If @errfd == @outfd (and non-NULL) they will be shared.
  20. *
  21. * The return value is the pid of the child, or -1.
  22. */
  23. pid_t pipecmd(int *infd, int *outfd, int *errfd, const char *cmd, ...);
  24. /**
  25. * pipecmdv - run a command, optionally connect pipes (stdarg version)
  26. * @infd: input fd to write to child (if non-NULL)
  27. * @outfd: output fd to read from child (if non-NULL)
  28. * @errfd: error-output fd to read from child (if non-NULL)
  29. * @cmd: command to run.
  30. * @ap: argument list for arguments.
  31. */
  32. pid_t pipecmdv(int *infd, int *outfd, int *errfd, const char *cmd, va_list ap);
  33. /**
  34. * pipecmdarr - run a command, optionally connect pipes (char arry version)
  35. * @infd: input fd to write to child (if non-NULL)
  36. * @outfd: output fd to read from child (if non-NULL)
  37. * @errfd: error-output fd to read from child (if non-NULL)
  38. * @arr: NULL-terminated array for arguments (first is program to run).
  39. */
  40. pid_t pipecmdarr(int *infd, int *outfd, int *errfd, char *const *arr);
  41. #endif /* CCAN_PIPECMD_H */