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 <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin
2018-10-12 22:41:18 +02:00
2 changed files with 15 additions and 0 deletions

View File

@@ -393,6 +393,9 @@ int mingw_raise(int sig);
int winansi_isatty(int fd);
#define isatty winansi_isatty
int winansi_dup2(int oldfd, int newfd);
#define dup2 winansi_dup2
void winansi_init(void);
HANDLE winansi_get_osfhandle(int fd);

View File

@@ -474,6 +474,18 @@ static void die_lasterr(const char *fmt, ...)
va_end(params);
}
#undef dup2
int winansi_dup2(int oldfd, int newfd)
{
int ret = dup2(oldfd, newfd);
if (!ret && newfd >= 0 && newfd <= 2)
fd_is_interactive[newfd] = oldfd < 0 || oldfd > 2 ?
0 : fd_is_interactive[oldfd];
return ret;
}
static HANDLE duplicate_handle(HANDLE hnd)
{
HANDLE hresult, hproc = GetCurrentProcess();