Index: terminal.c =================================================================== --- terminal.c (.../vendor/readline/readline-5.2) (revision 3519) +++ terminal.c (.../trunk/linphone/readline) (revision 3519) @@ -96,7 +96,7 @@ static int tcap_initialized; -#if !defined (__linux__) +#if !defined (__linux__) || defined (PDCURSES) # if defined (__EMX__) || defined (NEED_EXTERN_PC) extern # endif /* __EMX__ || NEED_EXTERN_PC */ Index: readline.c =================================================================== --- readline.c (.../vendor/readline/readline-5.2) (revision 3519) +++ readline.c (.../trunk/linphone/readline) (revision 3519) @@ -172,6 +172,11 @@ FILE *rl_instream = (FILE *)NULL; FILE *rl_outstream = (FILE *)NULL; +/* The name of the windows handle to do input using win32 api */ +#if defined (__MINGW32__) +HANDLE rl_inhandle = (HANDLE)NULL; +#endif + /* Non-zero means echo characters as they are read. Defaults to no echo; set to 1 if there is a controlling terminal, we can get its attributes, and the attributes include `echo'. Look at rltty.c:prepare_terminal_settings @@ -1008,6 +1013,11 @@ if (!rl_instream) rl_instream = stdin; +#if defined (__MINGW32__) + if (!rl_inhandle) + rl_inhandle = (HANDLE) _get_osfhandle (fileno (rl_instream)); +#endif + if (!rl_outstream) rl_outstream = stdout; Index: readline.h =================================================================== --- readline.h (.../vendor/readline/readline-5.2) (revision 3519) +++ readline.h (.../trunk/linphone/readline) (revision 3519) @@ -39,6 +39,12 @@ # include #endif +#if defined (__MINGW32__) +#include +#include +#undef FIONREAD +#endif + /* Hex-encoded Readline version number. */ #define RL_READLINE_VERSION 0x0502 /* Readline 5.2 */ #define RL_VERSION_MAJOR 5 @@ -531,7 +537,11 @@ /* The input and output streams. */ extern FILE *rl_instream; extern FILE *rl_outstream; +#if defined (__MINGW32__) +extern HANDLE rl_inhandle; +#endif + /* If non-zero, Readline gives values of LINES and COLUMNS from the environment greater precedence than values fetched from the kernel when computing the screen dimensions. */ Index: configure =================================================================== --- configure (.../vendor/readline/readline-5.2) (revision 3519) +++ configure (.../trunk/linphone/readline) (revision 3519) @@ -8447,6 +8447,7 @@ + SHLIB_LIBS=-lncurses @@ -8459,7 +8460,6 @@ - echo "$as_me:$LINENO: result: $SHLIB_STATUS" >&5 echo "${ECHO_T}$SHLIB_STATUS" >&6 Index: input.c =================================================================== --- input.c (.../vendor/readline/readline-5.2) (revision 3519) +++ input.c (.../trunk/linphone/readline) (revision 3519) @@ -76,6 +76,12 @@ #include "rlshell.h" #include "xmalloc.h" +#if defined (__MINGW32__) +#include +#include +#undef FIONREAD +#endif + /* What kind of non-blocking I/O do we have? */ #if !defined (O_NDELAY) && defined (O_NONBLOCK) # define O_NDELAY O_NONBLOCK /* Posix style */ @@ -179,6 +185,13 @@ struct timeval timeout; #endif +#if defined (__MINGW32__) + DWORD total_bytes_avail; + BOOL peek_ret_val; + WORD peek_buffer[10]; + DWORD bytes_read; +#endif + chars_avail = 0; tty = fileno (rl_instream); @@ -222,10 +235,30 @@ #endif /* O_NDELAY */ #if defined (__MINGW32__) - /* Use getch/_kbhit to check for available console input, in the same way - that we read it normally. */ - chars_avail = isatty (tty) ? _kbhit () : 0; - result = 0; + if (isatty (tty)) + { + /* If this is a Windows console then use getch/_kbhit to check for + * available input, in the same way that we read it normally. */ + chars_avail = _kbhit (); + + } + else + { + /* If this is a Windows pipe then use the Win32 api to see if there is + * available input.*/ + + bytes_read = 0; + peek_ret_val= PeekNamedPipe (rl_inhandle, + peek_buffer, + 9, + &bytes_read, + &total_bytes_avail, + 0); + + chars_avail = bytes_read; + } + + result = 0; #endif /* If there's nothing available, don't waste time trying to read