- if (fds[0] >= 0) {
- if (fds[0]) {
- close(in[1]);
- if (in[0] != STDIN_FILENO)
- dup2(in[0], STDIN_FILENO);
- } else
- dup2(null, STDIN_FILENO);
+ if (fds[0] == 0)
+ dup2(null, STDIN_FILENO);
+ else if (fds[0] > 0) {
+ close(in[1]);
+ if (in[0] != STDIN_FILENO)
+ dup2(in[0], STDIN_FILENO);
- if (fds[1] >= 0) {
- if (fds[1]) {
- close(out[0]);
- if (out[1] != STDOUT_FILENO)
- dup2(out[1], STDOUT_FILENO);
- } else
- dup2(null, STDOUT_FILENO);
+ if (fds[1] == 0)
+ dup2(null, STDOUT_FILENO);
+ else if (fds[1] > 0) {
+ close(out[0]);
+ if (out[1] != STDOUT_FILENO)
+ dup2(out[1], STDOUT_FILENO);
- if (fds[2] >= 0) {
- if (fds[2]) {
- close(err[0]);
- if (err[1] != STDERR_FILENO)
- dup2(err[1], STDERR_FILENO);
- } else
- dup2(null, STDERR_FILENO);
+ if (fds[2] == 0)
+ dup2(null, STDERR_FILENO);
+ else if (fds[2] > 0) {
+ close(err[0]);
+ if (err[1] != STDERR_FILENO)
+ dup2(err[1], STDERR_FILENO);
* \param fds A pointer to a value-result array.
*
* This function uses fork/exec to create a new process. \a fds must be a
* \param fds A pointer to a value-result array.
*
* This function uses fork/exec to create a new process. \a fds must be a
* - fd[i] > 0: create a pipe and dup i to one end of that pipe.
* Upon return, fd[i] contains the file descriptor of the pipe.
*
* - fd[i] > 0: create a pipe and dup i to one end of that pipe.
* Upon return, fd[i] contains the file descriptor of the pipe.
*