changeset 4761:feca2e26f367

Don't echo the password on Solaris, HP-UX, AIX, OSF/1.
author Bruno Haible <bruno@clisp.org>
date Wed, 01 Oct 2003 11:11:02 +0000
parents 0bb62f52421d
children f7021d78cdc7
files lib/ChangeLog lib/getpass.c
diffstat 2 files changed, 19 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,8 @@
+2003-10-01  Larry Jones  <lawrence.jones@eds.com>
+
+	* getpass.c (getpass): Use a no-op fseek when switching from input to
+	output mode on the same stream.
+
 2003-09-29  Paul Eggert  <eggert@twinsun.com>
 
 	* strftime.c (tm_diff) [! HAVE_TM_GMTOFF]:
--- a/lib/getpass.c
+++ b/lib/getpass.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1992,93,94,95,96,97,98,99,2000, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1992-2001, 2003 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    This program is free software; you can redistribute it and/or modify
@@ -22,6 +22,7 @@
 #include <stdio.h>
 #include <termios.h>
 #include <unistd.h>
+#include <fcntl.h>
 #include "getline.h"
 #include "unlocked-io.h"
 
@@ -84,8 +85,18 @@
 	  /* Remove the newline.  */
 	  buf[nread - 1] = '\0';
 	  if (tty_changed)
-	    /* Write the newline that was not echoed.  */
-	    putc ('\n', out);
+	    {
+	      /* Write the newline that was not echoed.
+		 But before doing that, do a no-op fseek.  According to the C
+		 standard, input may not be followed by output on the same
+		 stream without an intervening call to a file positioning
+		 function.  Without this fseek() call, on Solaris, HP-UX,
+		 AIX, OSF/1, the previous input gets echoed, whereas on IRIX,
+		 the following newline is not output as it should.  */
+	      if (out == in)
+		fseek (out, 0, SEEK_CUR);
+	      putc ('\n', out);
+	    }
 	}
     }