Index: port/sprompt.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/port/sprompt.c,v
retrieving revision 1.12
diff -c -r1.12 sprompt.c
*** port/sprompt.c	15 Oct 2005 02:49:51 -0000	1.12
--- port/sprompt.c	28 Feb 2006 19:36:29 -0000
***************
*** 40,47 ****
  {
  	int			length;
  	char	   *destination;
! 	FILE	   *termin,
! 			   *termout;
  
  #ifdef HAVE_TERMIOS_H
  	struct termios t_orig,
--- 40,47 ----
  {
  	int			length;
  	char	   *destination;
! 	FILE	   *termin = NULL,
! 			   *termout = NULL;
  
  #ifdef HAVE_TERMIOS_H
  	struct termios t_orig,
***************
*** 64,79 ****
  	 * some platforms (eg, HPUX 10.20).
  	 */
  	termin = fopen("/dev/tty", "r");
! 	termout = fopen("/dev/tty", "w");
! 	if (!termin || !termout)
! 	{
! 		if (termin)
! 			fclose(termin);
! 		if (termout)
! 			fclose(termout);
! 		termin = stdin;
! 		termout = stderr;
! 	}
  
  #ifdef HAVE_TERMIOS_H
  	if (!echo)
--- 64,87 ----
  	 * some platforms (eg, HPUX 10.20).
  	 */
  	termin = fopen("/dev/tty", "r");
!     if (!termin || !isatty(fileno(termin)))
!     {
!        if (termin)
!            fclose(termin);
!        termin = stdin;
!        termout = stderr;
!     } 
!     else
!     {
! 	   termout = fopen("/dev/tty", "w");
!        if (!termout)
!        {
!            if (termin)
!                fclose(termin);
!            termin = stdin;
!            termout = stderr;
!        }
!     }
  
  #ifdef HAVE_TERMIOS_H
  	if (!echo)
