X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=readline%2Finput.c;h=e35277fd2df13fb78b512eaac8a575778fcbade7;hb=7f3c5ec870943f7f32c946ff9459dfd04fcb8e07;hp=7c74c99508911f98889eec9c176f212a52c2766a;hpb=a3fa21cadc29421553d2c956056f0a777dafd3d2;p=deliverable%2Fbinutils-gdb.git diff --git a/readline/input.c b/readline/input.c index 7c74c99508..e35277fd2d 100644 --- a/readline/input.c +++ b/readline/input.c @@ -86,6 +86,36 @@ static int ibuffer_space PARAMS((void)); static int rl_get_char PARAMS((int *)); static int rl_gather_tyi PARAMS((void)); +#if defined (_WIN32) && !defined (__CYGWIN__) + +/* 'isatty' in the Windows runtime returns non-zero for every + character device, including the null device. Repair that. */ +#include +#define WIN32_LEAN_AND_MEAN 1 +#include + +int w32_isatty (int fd) +{ + if (_isatty(fd)) + { + HANDLE h = (HANDLE) _get_osfhandle (fd); + DWORD ignored; + + if (h == INVALID_HANDLE_VALUE) + { + errno = EBADF; + return 0; + } + if (GetConsoleMode (h, &ignored) != 0) + return 1; + } + errno = ENOTTY; + return 0; +} + +#define isatty(x) w32_isatty(x) +#endif + /* **************************************************************** */ /* */ /* Character Input Buffering */ @@ -465,8 +495,10 @@ rl_getc (stream) RL_CHECK_SIGNALS (); #if defined (__MINGW32__) + /* Use _getch to make sure we call the function from MS runtime, + even if some curses library is linked in. */ if (isatty (fileno (stream))) - return (getch ()); + return (_getch ()); #endif result = read (fileno (stream), &c, sizeof (unsigned char));