aboutsummaryrefslogtreecommitdiff
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
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>
-rw-r--r--include/mingw.h2
-rw-r--r--win32/winansi.c27
2 files changed, 29 insertions, 0 deletions
diff --git a/include/mingw.h b/include/mingw.h
index 197b3519a..ff5e8ee1e 100644
--- a/include/mingw.h
+++ b/include/mingw.h
@@ -420,6 +420,7 @@ int mingw_unlink(const char *pathname);
420NOIMPL(vfork,void); 420NOIMPL(vfork,void);
421int mingw_access(const char *name, int mode); 421int mingw_access(const char *name, int mode);
422int mingw_rmdir(const char *name); 422int mingw_rmdir(const char *name);
423int mingw_isatty(int fd);
423 424
424#define dup2 mingw_dup2 425#define dup2 mingw_dup2
425#define getcwd mingw_getcwd 426#define getcwd mingw_getcwd
@@ -432,6 +433,7 @@ int mingw_rmdir(const char *name);
432 433
433#undef access 434#undef access
434#define access mingw_access 435#define access mingw_access
436#define isatty mingw_isatty
435 437
436/* 438/*
437 * utime.h 439 * utime.h
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}