Back to index

glibc  2.9
mygetpass.c
Go to the documentation of this file.
00001 #include <termios.h>
00002 #include <stdio.h>
00003 
00004 ssize_t
00005 my_getpass (char **lineptr, size_t *n, FILE *stream)
00006 {
00007   struct termios old, new;
00008   int nread;
00009 
00010   /* Turn echoing off and fail if we can't.  */
00011   if (tcgetattr (fileno (stream), &old) != 0)
00012     return -1;
00013   new = old;
00014   new.c_lflag &= ~ECHO;
00015   if (tcsetattr (fileno (stream), TCSAFLUSH, &new) != 0)
00016     return -1;
00017   
00018   /* Read the password.  */
00019   nread = getline (lineptr, n, stream);
00020 
00021   /* Restore terminal.  */
00022   (void) tcsetattr (fileno (stream), TCSAFLUSH, &old);
00023   
00024   return nread;
00025 }