+#ifndef HAVE_GETPASS
+static int
+set_echo_if_tty(int on)
+{
+#ifdef _WIN32
+ DWORD mode;
+ HANDLE input_handle = GetStdHandle(STD_INPUT_HANDLE);
+
+ if (!GetConsoleMode(input_handle, &mode))
+ return 0;
+
+ if (on)
+ mode |= ENABLE_ECHO_INPUT;
+ else
+ mode &= ~ENABLE_ECHO_INPUT;
+
+ if (!SetConsoleMode(input_handle, mode))
+ return -1;
+ return 1;
+#else
+ return 0;
+#endif
+}
+#endif /* !HAVE_GETPASS */
+