1 /* Copyright (C) 1992,93,94,95,96,97,98,99 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
25 libc_hidden_proto(strlen)
26 libc_hidden_proto(tcsetattr)
27 libc_hidden_proto(tcgetattr)
28 libc_hidden_proto(setvbuf)
29 libc_hidden_proto(fopen)
30 libc_hidden_proto(fclose)
31 libc_hidden_proto(fileno)
32 libc_hidden_proto(fflush)
33 libc_hidden_proto(fgets)
34 libc_hidden_proto(fputs)
35 libc_hidden_proto(fputc)
36 libc_hidden_proto(putc)
37 libc_hidden_proto(__fputc_unlocked)
39 /* It is desirable to use this bit on systems that have it.
40 The only bit of terminal state we want to twiddle is echoing, which is
41 done in software; there is no need to change the state of the terminal
47 #define PWD_BUFFER_SIZE 256
56 static char buf[PWD_BUFFER_SIZE];
59 /* Try to write to and read from the terminal if we can.
60 If we can't open the terminal, use stderr and stdin. */
62 in = fopen ("/dev/tty", "r+");
71 /* Turn echoing off if it is on now. */
73 if (tcgetattr (fileno (in), &t) == 0)
75 /* Save the old one. */
78 t.c_lflag &= ~(ECHO|ISIG);
79 tty_changed = (tcsetattr (fileno (in), TCSAFLUSH|TCSASOFT, &t) == 0);
81 /* Disable buffering for read/write FILE to prevent problems with
82 * fseek and buffering for read/write auto-transitioning. */
83 setvbuf(in, NULL, _IONBF, 0);
89 /* Write the prompt. */
93 /* Read the password. */
94 fgets (buf, PWD_BUFFER_SIZE-1, in);
100 else if (buf[nread - 1] == '\n')
102 /* Remove the newline. */
103 buf[nread - 1] = '\0';
105 /* Write the newline that was not echoed. */
110 /* Restore the original setting. */
112 (void) tcsetattr (fileno (in), TCSAFLUSH|TCSASOFT, &s);
116 /* We opened the terminal; now close it. */