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 /* Only for console-connected Handles */
29 if ( GetFileType(h) == FILE_TYPE_CHAR ) {
30 if ( GetConsoleMode(h,&st) &&
31 SetConsoleMode(h, cooked ? (st | flgs) : st & ~flgs) ) {
40 set_console_echo__(int fd, int on)
44 DWORD flgs = ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT;
46 if ( (h = (HANDLE)_get_osfhandle(fd)) != INVALID_HANDLE_VALUE ) {
47 if ( GetConsoleMode(h,&st) &&
48 SetConsoleMode(h,( on ? (st | flgs) : (st & ~ENABLE_ECHO_INPUT))) ) {
56 get_console_echo__(int fd)
61 if ( (h = (HANDLE)_get_osfhandle(fd)) != INVALID_HANDLE_VALUE ) {
62 if ( GetConsoleMode(h,&st) ) {
63 return (st & ENABLE_ECHO_INPUT ? 1 : 0);
70 flush_input_console__(int fd)
72 HANDLE h = (HANDLE)_get_osfhandle(fd);
74 if ( h != INVALID_HANDLE_VALUE ) {
75 /* If the 'fd' isn't connected to a console; treat the flush
79 if ( !GetConsoleMode(h,&unused) &&
80 GetLastError() == ERROR_INVALID_HANDLE ) {
83 if ( FlushConsoleInputBuffer(h) ) {
87 /* ToDo: translate GetLastError() into something errno-friendly */
91 #endif /* defined(__MINGW32__) || ... */