aboutsummaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2017-06-30 22:19:49 +0200
committerRon Yorston <rmy@pobox.com>2017-08-24 09:12:10 +0100
commit98bc4759107c54783c08bf1ecde35e96f1345dc1 (patch)
treed93e890d91fe9506cdb1c0901306dc880589b227 /win32
parent0933725e0f33fa93256623933813381c62611bfd (diff)
downloadbusybox-w32-98bc4759107c54783c08bf1ecde35e96f1345dc1.tar.gz
busybox-w32-98bc4759107c54783c08bf1ecde35e96f1345dc1.tar.bz2
busybox-w32-98bc4759107c54783c08bf1ecde35e96f1345dc1.zip
mingw: accommodate for BusyBox' assumptions about isatty()
On Windows, isatty(fd) determines whether the file descriptor refers to a character device. The thing is: even NUL or a printer is a character device. BusyBox thinks, however, that isatty() only returns non-zero for an interactive terminal. So let's shadow isatty() by a version that answers the question BusyBox wants to have answered. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Ron Yorston <rmy@pobox.com>
Diffstat (limited to 'win32')
-rw-r--r--win32/winansi.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/win32/winansi.c b/win32/winansi.c
index 7c7e1a626..8fffc5a00 100644
--- a/win32/winansi.c
+++ b/win32/winansi.c
@@ -733,3 +733,30 @@ int winansi_getc(FILE *stream)
733 733
734 return rv; 734 return rv;
735} 735}
736
737/* Ensure that isatty(fd) returns 0 for the NUL device */
738int mingw_isatty(int fd)
739{
740 int result = _isatty(fd);
741
742 if (result) {
743 HANDLE handle = (HANDLE) _get_osfhandle(fd);
744 CONSOLE_SCREEN_BUFFER_INFO sbi;
745 DWORD mode;
746
747 if (handle == INVALID_HANDLE_VALUE)
748 return 0;
749
750 /* check if its a device (i.e. console, printer, serial port) */
751 if (GetFileType(handle) != FILE_TYPE_CHAR)
752 return 0;
753
754 if (!fd) {
755 if (!GetConsoleMode(handle, &mode))
756 return 0;
757 } else if (!GetConsoleScreenBufferInfo(handle, &sbi))
758 return 0;
759 }
760
761 return result;
762}