changeset 3611:9e3661edaad0

6515653 __getpass function outputs to stderr rather than tty
author craigm
date Wed, 07 Feb 2007 14:12:12 -0800
parents 7a2f3e83a236
children 5e2207694c21
files usr/src/lib/libc/port/stdio/getpass.c
diffstat 1 files changed, 4 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/lib/libc/port/stdio/getpass.c	Wed Feb 07 12:22:46 2007 -0800
+++ b/usr/src/lib/libc/port/stdio/getpass.c	Wed Feb 07 14:12:12 2007 -0800
@@ -19,7 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -80,7 +80,7 @@
 	rmutex_t *lk;
 
 	if (pbuf == NULL ||
-	    (fi = fopen("/dev/tty", "rF")) == NULL)
+	    (fi = fopen("/dev/tty", "r+F")) == NULL)
 		return (NULL);
 	setbuf(fi, NULL);
 	sig = signal(SIGINT, catch);
@@ -89,8 +89,7 @@
 	flags = ttyb.c_lflag;
 	ttyb.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
 	(void) ioctl(FILENO(fi), TCSETAF, &ttyb);
-	FLOCKFILE(lk, stderr);
-	(void) fputs(prompt, stderr);
+	(void) fputs(prompt, fi);
 	p = pbuf;
 	while (!intrupt &&
 		(c = GETC(fi)) != '\n' && c != '\r' && c != EOF) {
@@ -98,10 +97,9 @@
 			*p++ = (char)c;
 	}
 	*p = '\0';
+	(void) PUTC('\n', fi);
 	ttyb.c_lflag = flags;
 	(void) ioctl(FILENO(fi), TCSETAW, &ttyb);
-	(void) PUTC('\n', stderr);
-	FUNLOCKFILE(lk);
 	(void) signal(SIGINT, sig);
 	(void) fclose(fi);
 	if (intrupt)