Fix thinko.
[glibc.git] / manual / examples / mygetpass.c
blob6fe06f4637d1ba1c36e31a207020ad851fc6e316
1 #include <termios.h>
2 #include <stdio.h>
4 ssize_t
5 my_getpass (char **lineptr, size_t *n, FILE *stream)
7 struct termios old, new;
8 int nread;
10 /* Turn echoing off and fail if we can't. */
11 if (tcgetattr (fileno (stream), &old) != 0)
12 return -1;
13 new = old;
14 new.c_lflag &= ~ECHO;
15 if (tcsetattr (fileno (stream), TCSAFLUSH, &new) != 0)
16 return -1;
18 /* Read the password. */
19 nread = getline (lineptr, n, stream);
21 /* Restore terminal. */
22 (void) tcsetattr (fileno (stream), TCSAFLUSH, &old);
24 return nread;