added getpass implementation for non windows
modifies terminal attributes to emulate _getch
This commit is contained in:
parent
2741f23641
commit
d5e86752de
@ -7,6 +7,34 @@
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <conio.h>
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int _getch(void)
|
||||
{
|
||||
struct termios old, mute;
|
||||
int c;
|
||||
|
||||
tcgetattr(STDIN_FILENO, &old);
|
||||
mute = old;
|
||||
mute.c_lflag &= ~(ICANON|ECHO);
|
||||
|
||||
if (0 != tcsetattr(STDIN_FILENO, TCSANOW, &mute)) {
|
||||
/* XXX an error happened */
|
||||
/* We prefer to print the password, i.e. ignore the error,
|
||||
* rather than to deny the service, i.e. return something like '\0' */
|
||||
}
|
||||
|
||||
c = getchar();
|
||||
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &old);
|
||||
|
||||
return c;
|
||||
}
|
||||
#endif
|
||||
|
||||
char *getpass(const char *prompt)
|
||||
{
|
||||
static char buf[128];
|
||||
@ -23,7 +51,4 @@ char *getpass(const char *prompt)
|
||||
fputs("\n", stderr);
|
||||
return buf;
|
||||
}
|
||||
#else
|
||||
#error Need getpass implementation
|
||||
#endif
|
||||
#endif /* HAVE_GETPASS */
|
||||
|
Loading…
Reference in New Issue
Block a user