Skip to content

Commit fbfdc07

Browse files
committed
Merge branch 'js/mingw-isatty-and-dup2'
Windows fix. * js/mingw-isatty-and-dup2: mingw: fix isatty() after dup2()
2 parents bce4fc6 + ff8978d commit fbfdc07

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
@@ -406,6 +406,9 @@ int mingw_raise(int sig);
406406
int winansi_isatty(int fd);
407407
#define isatty winansi_isatty
408408

409+
int winansi_dup2(int oldfd, int newfd);
410+
#define dup2 winansi_dup2
411+
409412
void winansi_init(void);
410413
HANDLE winansi_get_osfhandle(int fd);
411414

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)