Skip to content

Commit 4876911

Browse files
committed
Merge branch 'mingw-isatty-and-dup2'
In December 2016 and January 2017, we revamped the Windows-specific `isatty()` handling, replacing a hack by a more robust solution. This patch is a follow-up we realized was necessary already in March 2017, but forgot to contribute to core Git yet. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 87a58f1 + 2237b19 commit 4876911

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

compat/mingw.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,9 @@ int mingw_raise(int sig);
417417
int winansi_isatty(int fd);
418418
#define isatty winansi_isatty
419419

420+
int winansi_dup2(int oldfd, int newfd);
421+
#define dup2 winansi_dup2
422+
420423
void winansi_init(void);
421424
HANDLE winansi_get_osfhandle(int fd);
422425

compat/winansi.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,18 @@ static void die_lasterr(const char *fmt, ...)
474474
va_end(params);
475475
}
476476

477+
#undef dup2
478+
int winansi_dup2(int oldfd, int newfd)
479+
{
480+
int ret = dup2(oldfd, newfd);
481+
482+
if (!ret && newfd >= 0 && newfd <= 2)
483+
fd_is_interactive[newfd] = oldfd < 0 || oldfd > 2 ?
484+
0 : fd_is_interactive[oldfd];
485+
486+
return ret;
487+
}
488+
477489
static HANDLE duplicate_handle(HANDLE hnd)
478490
{
479491
HANDLE hresult, hproc = GetCurrentProcess();

0 commit comments

Comments
 (0)