Avoid trying to open /dev/tty on Win32. Some Win32 systems have
authorBruce Momjian <[email protected]>
Fri, 3 Mar 2006 23:49:21 +0000 (23:49 +0000)
committerBruce Momjian <[email protected]>
Fri, 3 Mar 2006 23:49:21 +0000 (23:49 +0000)
/dev/tty, but it isn't a device file and doesn't work as expected.

This fixes a known bug where psql does not prompt for a password on some
Win32 systems.

Backpatch to 8.1.X.

Robert Kinberg

src/bin/psql/command.c
src/port/sprompt.c

index db5b1d36c66fbe962241128166785eb7ec3f1f21..c52d4a5b42ed41271fe4f311f462c253133d5cec 100644 (file)
@@ -659,8 +659,11 @@ exec_command(const char *cmd,
 
                expand_tilde(&fname);
                /* This scrolls off the screen when using /dev/tty */
+#ifndef WIN32
                success = saveHistory(fname ? fname : "/dev/tty");
-
+#else
+               success = saveHistory(fname ? fname : stderr);
+#endif
                if (success && !quiet && fname)
                        printf(gettext("Wrote history to file \"%s/%s\".\n"),
                                   pset.dirname ? pset.dirname : ".", fname);
index 79a8b7528f26f19b0279787fca1a9966e72250d0..2211f813ef118413ca8ecf05280d38f4bd4addaf 100644 (file)
@@ -40,8 +40,8 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
 {
        int                     length;
        char       *destination;
-       FILE       *termin,
-                          *termout;
+       FILE       *termin = NULL,
+                          *termout = NULL;
 
 #ifdef HAVE_TERMIOS_H
        struct termios t_orig,
@@ -63,8 +63,14 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
         * Do not try to collapse these into one "w+" mode file. Doesn't work on
         * some platforms (eg, HPUX 10.20).
         */
+#ifndef WIN32
+       /*
+        *      Some win32 platforms actually have a /dev/tty file, but it isn't
+        *      a device file, and it doesn't work as expected, so we avoid trying.
+        */
        termin = fopen("/dev/tty", "r");
        termout = fopen("/dev/tty", "w");
+#endif
        if (!termin || !termout)
        {
                if (termin)