#endif
/*
- * There are 5 types of terminal interface supported, TERMIO, TERMIOS, VMS,
- * MSDOS and SGTTY.
+ * There are 6 types of terminal interface supported, TERMIO, TERMIOS, VMS,
+ * MSDOS, WIN32 Console and SGTTY.
*
* If someone defines one of the macros TERMIO, TERMIOS or SGTTY, it will
* remain respected. Otherwise, we default to TERMIOS except for a few
# undef SGTTY
/*
* We know that VMS, MSDOS, VXWORKS, use entirely other mechanisms.
- * MAC_OS_GUSI_SOURCE should probably go away, but that needs to be confirmed.
*/
# elif !defined(OPENSSL_SYS_VMS) \
&& !defined(OPENSSL_SYS_MSDOS) \
- && !defined(MAC_OS_GUSI_SOURCE) \
&& !defined(OPENSSL_SYS_VXWORKS)
# define TERMIOS
# undef TERMIO
};
#endif
-#if defined(MAC_OS_GUSI_SOURCE)
-/*
- * This one needs work. As a matter of fact the code is unoperational
- * and this is only a trick to get it compiled.
- * <appro@fy.chalmers.se>
- */
-# define TTY_STRUCT int
-#endif
-
#ifndef NX509_SIG
# define NX509_SIG 32
#endif
* structures? */
static long status;
static unsigned short channel = 0;
+#elif defined(_WIN32) && !defined(_WIN32_WCE)
+static DWORD tty_orig, tty_new;
#else
# if !defined(OPENSSL_SYS_MSDOS) || defined(__DJGPP__)
static TTY_STRUCT tty_orig, tty_new;
static void pushsig(void);
static void popsig(void);
#endif
-#if defined(OPENSSL_SYS_MSDOS)
+#if defined(OPENSSL_SYS_MSDOS) && !defined(_WIN32)
static int noecho_fgets(char *buf, int size, FILE *tty);
#endif
static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl);
char result[BUFSIZ];
int maxsize = BUFSIZ - 1;
#if !defined(OPENSSL_SYS_WINCE)
- char *p;
+ char *p = NULL;
+ int echo_eol = !echo;
intr_signal = 0;
ok = 0;
ps = 2;
result[0] = '\0';
-# ifdef OPENSSL_SYS_MSDOS
+# if defined(_WIN32)
+ if (is_a_tty) {
+ DWORD numread;
+# if defined(CP_UTF8)
+ WCHAR wresult[BUFSIZ];
+
+ if (ReadConsoleW(GetStdHandle(STD_INPUT_HANDLE),
+ wresult, maxsize, &numread, NULL)) {
+ if (numread >= 2 &&
+ wresult[numread-2] == L'\r' && wresult[numread-1] == L'\n') {
+ wresult[numread-2] = L'\n';
+ numread--;
+ echo_eol = 0;
+ }
+ wresult[numread] = '\0';
+ if (WideCharToMultiByte(CP_UTF8, 0, wresult, -1,
+ result, sizeof(result), NULL, 0) > 0)
+ p = result;
+
+ OPENSSL_cleanse(wresult, sizeof(wresult));
+ }
+# else
+ if (ReadConsoleA(GetStdHandle(STD_INPUT_HANDLE),
+ result, maxsize, &numread, NULL)) {
+ if (numread >= 2 &&
+ result[numread-2] == '\r' && result[numread-1] == '\n') {
+ result[numread-2] = '\n';
+ numread--;
+ echo_eol = 0;
+ }
+ result[numread] = '\0';
+ p = result;
+ }
+# endif
+ } else
+# elif defined(OPENSSL_SYS_MSDOS)
if (!echo) {
noecho_fgets(result, maxsize, tty_in);
p = result; /* FIXME: noecho_fgets doesn't return errors */
} else
- p = fgets(result, maxsize, tty_in);
-# else
- p = fgets(result, maxsize, tty_in);
# endif
+ p = fgets(result, maxsize, tty_in);
if (!p)
goto error;
if (feof(tty_in))
error:
if (intr_signal == SIGINT)
ok = -1;
- if (!echo)
+ if (echo_eol)
fprintf(tty_out, "\n");
if (ps >= 2 && !echo && !echo_console(ui))
ok = 0;
#if defined(OPENSSL_SYS_VXWORKS)
tty_in = stdin;
tty_out = stderr;
+#elif defined(_WIN32) && !defined(_WIN32_WCE)
+ if ((tty_out = fopen("conout$", "w")) == NULL)
+ tty_out = stderr;
+
+ if (GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &tty_orig)) {
+ tty_in = stdin;
+ } else {
+ is_a_tty = 0;
+ if ((tty_in = fopen("conin$", "r")) == NULL)
+ tty_in = stdin;
+ }
#else
# ifdef OPENSSL_SYS_MSDOS
# define DEV_TTY "con"
0);
if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
return 0;
+#endif
+#if defined(_WIN32) && !defined(_WIN32_WCE)
+ if (is_a_tty) {
+ tty_new = tty_orig;
+ tty_new &= ~ENABLE_ECHO_INPUT;
+ SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), tty_new);
+ }
#endif
return 1;
}
0);
if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
return 0;
+#endif
+#if defined(_WIN32) && !defined(_WIN32_WCE)
+ if (is_a_tty) {
+ tty_new = tty_orig;
+ tty_new |= ENABLE_ECHO_INPUT;
+ SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), tty_new);
+ }
#endif
return 1;
}
#endif
/* Internal functions specific for Windows */
-#if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WINCE)
+#if defined(OPENSSL_SYS_MSDOS) && !defined(_WIN32)
static int noecho_fgets(char *buf, int size, FILE *tty)
{
int i;