diff options
author | Ulrich Drepper <drepper@redhat.com> | 1997-01-06 22:07:28 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 1997-01-06 22:07:28 +0000 |
commit | df4ef2ab9c0899b2670067cd97e58f7eb2913e00 (patch) | |
tree | 4cb343b5ba9ccdc9c0b96144412567b6a4eda0ee /misc/getpass.c | |
parent | 6f9e7002f38ae778b3ff2f586a3e5766382228e9 (diff) | |
download | glibc-df4ef2ab9c0899b2670067cd97e58f7eb2913e00.zip glibc-df4ef2ab9c0899b2670067cd97e58f7eb2913e00.tar.gz glibc-df4ef2ab9c0899b2670067cd97e58f7eb2913e00.tar.bz2 |
update from main archive 960105cvs/libc-970107cvs/libc-970106
Diffstat (limited to 'misc/getpass.c')
-rw-r--r-- | misc/getpass.c | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/misc/getpass.c b/misc/getpass.c index 81c0f68..74af9b5 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. */ |