Workaround for a Win95 console bug triggered by the password read stuff.
[openssl.git] / crypto / des / read_pwd.c
index 3041ab2dfe8ebaa1ea80888969fc5b590cc374d5..edfa456a43905ae5a20f8a4546041fec8edb1d90 100644 (file)
 #include <graph.h>
 #endif
 
+#if defined(WIN32) && !defined(WINNT)
+#define WIN_CONSOLE_BUG
+#endif
+
+
 /* 06-Apr-92 Luke Brennan    Support for VMS */
 #include "des_locl.h"
 #include <signal.h>
 #include <setjmp.h>
 #include <errno.h>
 
+#ifdef WIN_CONSOLE_BUG
+#include <windows.h>
+#include <wincon.h>
+#endif
+
+
 /* There are 5 types of terminal interface supported,
  * TERMIO, TERMIOS, VMS, MSDOS and SGTTY
  */
@@ -462,6 +473,18 @@ FILE *tty;
                        break;
                        }
                }
+#ifdef WIN_CONSOLE_BUG
+/* Win95 has several evil console bugs: one of these is that the
+ * last character read using getch() is passed to the next read: this is
+ * usually a CR so this can be trouble. No STDIO fix seems to work but
+ * flushing the console appears to do the trick.
+ */
+                {
+                        HANDLE inh;
+                        inh = GetStdHandle(STD_INPUT_HANDLE);
+                        FlushConsoleInputBuffer(inh);
+                }
+#endif
        return(strlen(buf));
        }
 #endif