3 * gcc echo_off -o echo_off -Wall -W -Wextra -ansi -pedantic
5 * Whenever a user types in a password, it is desirable that
6 * the password itself doesn't show up at all. To implement
7 * such behaviour, we use the termios(4) interface to disable
18 /* Function prototypes */
19 void diep(const char *s
);
21 int main(int argc
, char *argv
[])
23 struct termios oldt
, newt
;
24 char password
[PASSLEN
];
27 /* Check argument count */
29 fprintf(stderr
, "Usage: %s tty\n", argv
[0]);
33 /* Open terminal device */
34 if ((fd
= open(argv
[1], O_RDONLY
| O_NOCTTY
) == -1))
37 /* Get current termios structure */
38 if (tcgetattr(fd
, &oldt
) == -1)
41 /* Set new termios structure */
43 newt
.c_lflag
&= ~ECHO
; /* disable echoing */
44 newt
.c_lflag
|= ECHONL
; /* echo NL even if ECHO is off */
46 if (tcsetattr(fd
, TCSANOW
, &newt
) == -1)
49 /* Prompt for password and get it */
51 fgets(password
, PASSLEN
, stdin
);
53 /* Restore old termios structure */
54 if (tcsetattr(fd
, TCSANOW
, &oldt
) == -1)
60 void diep(const char *s
)