diff -ruN psql/common.c psql_patched/common.c --- psql/common.c Sun Apr 15 02:43:37 2001 +++ psql_patched/common.c Sun Oct 7 14:58:22 2001 @@ -176,6 +176,7 @@ { int length; char *destination; + static FILE *term = NULL; #ifdef HAVE_TERMIOS_H struct termios t_orig, @@ -190,24 +191,28 @@ fputs(prompt, stderr); prompt_state = true; + if (!term) + term = fopen("/dev/tty", "r"); + if (term == NULL) + term = stdin; #ifdef HAVE_TERMIOS_H if (!echo) { - tcgetattr(0, &t); + tcgetattr(fileno(term), &t); t_orig = t; t.c_lflag &= ~ECHO; - tcsetattr(0, TCSADRAIN, &t); + tcsetattr(fileno(term), TCSADRAIN, &t); } #endif - if (fgets(destination, maxlen, stdin) == NULL) + if (fgets(destination, maxlen, term) == NULL) destination[0] = '\0'; #ifdef HAVE_TERMIOS_H if (!echo) { - tcsetattr(0, TCSADRAIN, &t_orig); + tcsetattr(fileno(term), TCSADRAIN, &t_orig); fputs("\n", stderr); } #endif @@ -223,7 +228,7 @@ do { - if (fgets(buf, sizeof(buf), stdin) == NULL) + if (fgets(buf, sizeof(buf), term) == NULL) break; buflen = strlen(buf); } while (buflen > 0 && buf[buflen - 1] != '\n');