getpass() is traditional Unix, but has been withdrawn from POSIX. We
provide a replacement in case it's missing. The one for Windows
suppresses echo, like getpass() does. Implement that for POSIX. The
other differences to getpass() remain.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
#include <string.h>
#ifdef _WIN32
#include <windows.h>
+#else
+#include <termios.h>
#endif
#endif
#include "misc.h"
return -1;
return 1;
#else
- return 0;
+ struct termios tcattr;
+
+ if (tcgetattr(0, &tcattr) < 0)
+ return 0;
+
+ if (on)
+ tcattr.c_lflag |= ECHO;
+ else
+ tcattr.c_lflag &= ~ECHO;
+
+ if (tcsetattr(0, TCSAFLUSH, &tcattr) < 0)
+ return -1;
+ return 1;
#endif
}
#endif /* !HAVE_GETPASS */