diff options
author | Edward Z. Yang <ezyang@mit.edu> | 2010-09-07 15:41:44 +0000 |
---|---|---|
committer | Edward Z. Yang <ezyang@mit.edu> | 2010-09-07 15:41:44 +0000 |
commit | e7f7ce78c9e7416f5b2b2ce6f3997e5d322f31eb (patch) | |
tree | 64ca44c3481aaa2f8e89da5c708c0fea3c734c33 /libraries/base/cbits/consUtils.c | |
parent | 3e3cfe97d67591850a2e43231959910413044e09 (diff) | |
download | haskell-e7f7ce78c9e7416f5b2b2ce6f3997e5d322f31eb.tar.gz |
More accurate isatty test for MinGW.
Diffstat (limited to 'libraries/base/cbits/consUtils.c')
-rw-r--r-- | libraries/base/cbits/consUtils.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/libraries/base/cbits/consUtils.c b/libraries/base/cbits/consUtils.c index 7c50c7b9b5..55266b44db 100644 --- a/libraries/base/cbits/consUtils.c +++ b/libraries/base/cbits/consUtils.c @@ -14,6 +14,29 @@ #define _get_osfhandle get_osfhandle #endif +int is_console__(int fd) { + DWORD st; + HANDLE h; + if (!_isatty(fd)) { + /* TTY must be a character device */ + return 0; + } + h = get_osfhandle(fd); + if (h == INVALID_HANDLE_VALUE) { + /* Broken handle can't be terminal */ + return 0; + } + if (GetConsoleMode(h, &st) == INVALID_HANDLE_VALUE) { + /* GetConsoleMode appears to fail when it's not a TTY. In + particular, it's what most of our terminal functions + assume works, so if it doesn't work for all intents + and purposes we're not dealing with a terminal. */ + return 0; + } + return 1; +} + + int set_console_buffering__(int fd, int cooked) { |