2 * (c) The University of Glasgow 2002
4 * Win32 Console API support
6 #if defined(_MSC_VER) || defined(__MINGW32__) || defined(_WIN32) || defined(__CYGWIN__)
13 #if defined(__CYGWIN__)
14 #define _get_osfhandle get_osfhandle
18 set_console_buffering__(int fd, int cooked)
22 /* According to GetConsoleMode() docs, it is not possible to
23 leave ECHO_INPUT enabled without also having LINE_INPUT,
24 so we have to turn both off here. */
25 DWORD flgs = ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT;
27 if ( (h = (HANDLE)_get_osfhandle(fd)) != INVALID_HANDLE_VALUE ) {
28 if ( GetConsoleMode(h,&st) &&
29 SetConsoleMode(h, cooked ? (st | ENABLE_LINE_INPUT) : st & ~flgs) ) {
37 set_console_echo__(int fd, int on)
41 DWORD flgs = ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT;
43 if ( (h = (HANDLE)_get_osfhandle(fd)) != INVALID_HANDLE_VALUE ) {
44 if ( GetConsoleMode(h,&st) &&
45 SetConsoleMode(h,( on ? (st | flgs) : (st & ~ENABLE_ECHO_INPUT))) ) {
53 get_console_echo__(int fd)
58 if ( (h = (HANDLE)_get_osfhandle(fd)) != INVALID_HANDLE_VALUE ) {
59 if ( GetConsoleMode(h,&st) ) {
60 return (st & ENABLE_ECHO_INPUT ? 1 : 0);
67 flush_input_console__(int fd)
69 HANDLE h = (HANDLE)_get_osfhandle(fd);
71 if ( h != INVALID_HANDLE_VALUE ) {
72 /* If the 'fd' isn't connected to a console; treat the flush
76 if ( !GetConsoleMode(h,&unused) &&
77 GetLastError() == ERROR_INVALID_HANDLE ) {
80 if ( FlushConsoleInputBuffer(h) ) {
84 /* ToDo: translate GetLastError() into something errno-friendly */
88 #endif /* defined(__MINGW32__) || ... */