From 531ad70c792a01b1e3e8b8a52c3918f44956ee29 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Tue, 5 Oct 2010 12:57:09 +0000 Subject: [PATCH] Remove useless PARENT_FD/CHILD_FD hack. --- src/myfork.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/myfork.c b/src/myfork.c index 8bc4292..517960a 100644 --- a/src/myfork.c +++ b/src/myfork.c @@ -74,14 +74,6 @@ static int run_process(struct child *child, struct opts *, int[][2]); -#if defined HAVE_WINDOWS_H -# define PARENT_FD(x) ((x) ? 0 : 1) -# define CHILD_FD(x) ((x) ? 1 : 0) -#else -# define PARENT_FD(x) 0 -# define CHILD_FD(x) 1 -#endif - #if defined HAVE_WINDOWS_H static void rep32(uint8_t *buf, void *addr); static int dll_inject(PROCESS_INFORMATION *, char const *); @@ -105,9 +97,9 @@ int myfork(struct child *child, struct opts *opts) /* The pipe is created with NOINHERIT otherwise both parts are * inherited. We then duplicate the part we want. */ ret = _pipe(pipes[i], 512, _O_BINARY | O_NOINHERIT); - tmp = _dup(pipes[i][CHILD_FD(i)]); - close(pipes[i][CHILD_FD(i)]); - pipes[i][CHILD_FD(i)] = tmp; + tmp = _dup(pipes[i][1]); + close(pipes[i][1]); + pipes[i][1] = tmp; #endif if(ret < 0) { @@ -127,8 +119,8 @@ int myfork(struct child *child, struct opts *opts) child->pid = pid; for(i = 0; i < 3; i++) { - close(pipes[i][CHILD_FD(i)]); - child->fd[i] = pipes[i][PARENT_FD(i)]; + close(pipes[i][1]); + child->fd[i] = pipes[i][0]; } return 0; @@ -279,9 +271,9 @@ static int run_process(struct child *child, struct opts *opts, int pipes[][2]) /* Inherit standard handles */ memset(&sinfo, 0, sizeof(sinfo)); sinfo.cb = sizeof(sinfo); - sinfo.hStdInput = (HANDLE)_get_osfhandle(pipes[0][CHILD_FD(0)]); - sinfo.hStdOutput = (HANDLE)_get_osfhandle(pipes[1][CHILD_FD(1)]); - sinfo.hStdError = (HANDLE)_get_osfhandle(pipes[2][CHILD_FD(2)]); + sinfo.hStdInput = INVALID_HANDLE_VALUE; + sinfo.hStdOutput = (HANDLE)_get_osfhandle(pipes[2][1]); + sinfo.hStdError = (HANDLE)_get_osfhandle(pipes[1][1]); sinfo.dwFlags = STARTF_USESTDHANDLES; /* Build the commandline */