summaryrefslogtreecommitdiff
path: root/libc/unistd/getpass.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2002-04-09 13:25:11 +0000
committerEric Andersen <andersen@codepoet.org>2002-04-09 13:25:11 +0000
commitcaab797645993fad63cb769c172dd9c2b683752c (patch)
tree8a74b397d8fd721431857dc0ce620c4c0bd306d0 /libc/unistd/getpass.c
parentacda8279a233adec6479da7d1754a2e3829a9cc9 (diff)
Per discussion on the mailing list, fix getpass properly.
-Erik
Diffstat (limited to 'libc/unistd/getpass.c')
-rw-r--r--libc/unistd/getpass.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/libc/unistd/getpass.c b/libc/unistd/getpass.c
index 83b0140c7..8ebc985df 100644
--- a/libc/unistd/getpass.c
+++ b/libc/unistd/getpass.c
@@ -61,8 +61,10 @@ getpass (prompt)
/* Save the old one. */
s = t;
/* Tricky, tricky. */
- t.c_lflag &= ~(ECHO|ICANON|ISIG);
+ t.c_lflag &= ~(ECHO|ISIG);
tty_changed = (tcsetattr (fileno (in), TCSAFLUSH|TCSASOFT, &t) == 0);
+ /* Disable buffering for input FILE to prevent the buffering from flushing. */
+ setvbuf(in, NULL, _IOLBF, 0);
}
else
tty_changed = 0;
@@ -89,8 +91,11 @@ getpass (prompt)
}
/* Restore the original setting. */
- if (tty_changed)
+ if (tty_changed) {
(void) tcsetattr (fileno (in), TCSAFLUSH|TCSASOFT, &s);
+ /* Re-enable buffering. */
+ setlinebuf(in);
+ }
if (in != stdin)
/* We opened the terminal; now close it. */