2 gcc echo_off -o echo_off -Wall -W -Wextra -ansi -pedantic
4 Whenever a user types in a password, it is desirable that
5 the password itself doesn't show up at all. To implement
6 such behaviour, we use the termios(4) interface to disable
17 /* function prototypes */
18 void diep(const char *s
);
20 int main(int argc
, char *argv
[])
22 struct termios oldt
, newt
;
23 char password
[PASSLEN
];
26 /* check argument count */
28 fprintf(stderr
, "Usage: %s tty\n", argv
[0]);
32 /* open terminal device */
33 if ((fd
= open(argv
[1], O_RDONLY
| O_NOCTTY
) == -1))
36 /* get current termios structure */
37 if (tcgetattr(fd
, &oldt
) == -1)
40 /* set new termios structure */
42 newt
.c_lflag
&= ~ECHO
; /* disable echoing */
43 newt
.c_lflag
|= ECHONL
; /* echo NL even if ECHO is off */
45 if (tcsetattr(fd
, TCSANOW
, &newt
) == -1)
48 /* prompt for password and get it */
50 fgets(password
, PASSLEN
, stdin
);
52 /* restore old termios structure */
53 if (tcsetattr(fd
, TCSANOW
, &oldt
) == -1)
59 void diep(const char *s
)