about summary refs log tree commit diff
path: root/misc/getpass.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1997-01-06 22:07:28 +0000
committerUlrich Drepper <drepper@redhat.com>1997-01-06 22:07:28 +0000
commitdf4ef2ab9c0899b2670067cd97e58f7eb2913e00 (patch)
tree4cb343b5ba9ccdc9c0b96144412567b6a4eda0ee /misc/getpass.c
parent6f9e7002f38ae778b3ff2f586a3e5766382228e9 (diff)
downloadglibc-df4ef2ab9c0899b2670067cd97e58f7eb2913e00.tar.gz
glibc-df4ef2ab9c0899b2670067cd97e58f7eb2913e00.tar.xz
glibc-df4ef2ab9c0899b2670067cd97e58f7eb2913e00.zip
update from main archive 960105 cvs/libc-970107 cvs/libc-970106
Diffstat (limited to 'misc/getpass.c')
-rw-r--r--misc/getpass.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/misc/getpass.c b/misc/getpass.c
index 81c0f689de..74af9b5dc7 100644
--- a/misc/getpass.c
+++ b/misc/getpass.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1992,1993,1994,1995,1996 Free Software Foundation, Inc.
+/* Copyright (C) 1992, 93, 94, 95, 96, 97 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -34,8 +34,8 @@ getpass (prompt)
      const char *prompt;
 {
   FILE *in, *out;
-  struct termios t;
-  int echo_off;
+  struct termios s, t;
+  int tty_changed;
   static char *buf = NULL;
   static size_t bufsize = 0;
   ssize_t nread;
@@ -56,17 +56,16 @@ getpass (prompt)
 
   if (tcgetattr (fileno (in), &t) == 0)
     {
-      if (t.c_lflag & ECHO)
-	{
-	  t.c_lflag &= ~ECHO;
-	  echo_off = tcsetattr (fileno (in), TCSAFLUSH|TCSASOFT, &t) == 0;
-	  t.c_lflag |= ECHO;
-	}
-      else
-	echo_off = 0;
+      /* Save the old one. */
+      s = t;
+      /* Tricky, tricky. */
+      t.c_lflag &= ~(ECHO|ISIG|ICANON);
+      t.c_cc[VTIME] = 0;
+      t.c_cc[VMIN] = 1;
+      tty_changed = (tcsetattr (fileno (in), TCSAFLUSH|TCSASOFT, &t) == 0);
     }
   else
-    echo_off = 0;
+    tty_changed = 0;
 
   /* Write the prompt.  */
   fputs (prompt, out);
@@ -81,14 +80,14 @@ getpass (prompt)
       {
 	/* Remove the newline.  */
 	buf[nread - 1] = '\0';
-	if (echo_off)
+	if (tty_changed)
 	  /* Write the newline that was not echoed.  */
 	  putc ('\n', out);
       }
 
-  /* Restore echoing.  */
-  if (echo_off)
-    (void) tcsetattr (fileno (in), TCSAFLUSH|TCSASOFT, &t);
+  /* Restore the original setting.  */
+  if (tty_changed)
+    (void) tcsetattr (fileno (in), TCSAFLUSH|TCSASOFT, &s);
 
   if (in != stdin)
     /* We opened the terminal; now close it.  */