# [PATCH] run-command: fix build on cygwin (stdin is a macro)

3 messages from 2016-10-05 to 2016-10-06. Participants: Ramsay Jones, Torsten Bögershausen, Johannes Schindelin.
Thread: https://gitlist.dev/t/44228

## Ramsay Jones, 2016-10-05 20:19

Subject: [PATCH] run-command: fix build on cygwin (stdin is a macro)
Message-ID: <f9b6abf6-8305-4a32-29af-765f08fee94b@ramsayjones.plus.com>
URL: https://gitlist.dev/e/f9b6abf6-8305-4a32-29af-765f08fee94b%40ramsayjones.plus.com

```

Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
---

Hi Lars,

Commit 6007c69e ("run-command: add wait_on_exit", 04-10-2016), which
is part of your 'ls/filter-process' branch, causes the build to fail
on cygwin, since 'stdin' is defined as a macro thus:

    #define stdin   (_REENT->_stdin)

(you can probably guess what stdout and stderr look like!) where _REENT
in turn expands to a function call (__getreent()) which returns a pointer
to a 'struct _reent', etc., ...

I am not suggesting that you apply this exact patch (stdin_ is not a good
choice), but I wanted to show the exact patch I used to get the build to
complete on cygwin.

ATB,
Ramsay Jones

 run-command.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/run-command.c b/run-command.c
index 96c54fe..a9dd91a 100644
--- a/run-command.c
+++ b/run-command.c
@@ -22,7 +22,7 @@ void child_process_clear(struct child_process *child)
 struct child_to_clean {
 	pid_t pid;
 	char *name;
-	int stdin;
+	int stdin_;
 	int wait;
 	struct child_to_clean *next;
 };
@@ -37,8 +37,8 @@ static void cleanup_children(int sig, int in_signal)
 	/* Close the the child's stdin as indicator that Git will exit soon */
 	while (p) {
 		if (p->wait)
-			if (p->stdin > 0)
-				close(p->stdin);
+			if (p->stdin_ > 0)
+				close(p->stdin_);
 		p = p->next;
 	}
 
@@ -73,12 +73,12 @@ static void cleanup_children_on_exit(void)
 	cleanup_children(SIGTERM, 0);
 }
 
-static void mark_child_for_cleanup(pid_t pid, const char *name, int stdin, int wait)
+static void mark_child_for_cleanup(pid_t pid, const char *name, int stdin_, int wait)
 {
 	struct child_to_clean *p = xmalloc(sizeof(*p));
 	p->pid = pid;
 	p->wait = wait;
-	p->stdin = stdin;
+	p->stdin_ = stdin_;
 	if (name)
 		p->name = xstrdup(name);
 	else
@@ -94,7 +94,7 @@ static void mark_child_for_cleanup(pid_t pid, const char *name, int stdin, int w
 }
 
 #ifdef NO_PTHREADS
-static void mark_child_for_cleanup_no_wait(pid_t pid, const char *name, int timeout, int stdin)
+static void mark_child_for_cleanup_no_wait(pid_t pid, const char *name, int timeout, int stdin_)
 {
 	mark_child_for_cleanup(pid, NULL, 0, 0);
 }
-- 
2.10.0

```

## Torsten Bögershausen, 2016-10-06 05:13

Subject: Re: [PATCH] run-command: fix build on cygwin (stdin is a macro)
Message-ID: <7de3821f-5111-47ac-b7e5-20fe1216ba58@web.de>
URL: https://gitlist.dev/e/7de3821f-5111-47ac-b7e5-20fe1216ba58%40web.de
In-Reply-To: <f9b6abf6-8305-4a32-29af-765f08fee94b@ramsayjones.plus.com>

```
 >I am not suggesting that you apply this exact patch (stdin_ is not a good
choice

How about fd_stdin ?

```

## Johannes Schindelin, 2016-10-06 09:58

Subject: Re: [PATCH] run-command: fix build on cygwin (stdin is a macro)
Message-ID: <alpine.DEB.2.20.1610061157090.35196@virtualbox>
URL: https://gitlist.dev/e/alpine.DEB.2.20.1610061157090.35196%40virtualbox
In-Reply-To: <7de3821f-5111-47ac-b7e5-20fe1216ba58@web.de>

```
Hi,

On Thu, 6 Oct 2016, Torsten Bögershausen wrote:

> >I am not suggesting that you apply this exact patch (stdin_ is not a good
> choice
> 
> How about fd_stdin ?

Better: stdin_fd. Why? Prior art:

	$ git grep -c stdin_fd
	builtin/remote-ext.c:3

	$ git grep -c fd_stdin

Ciao,
Dscho
```
