diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2005-10-03 13:43:40 +0000 |
---|---|---|
committer | <> | 2014-09-25 11:25:48 +0000 |
commit | 10de491ef0bc43827ab8631a4c02860134e620a9 (patch) | |
tree | 22e734337cc9aa5d9b1d7c71261d160b6a60634d /os2/getpass.c | |
download | cvs-tarball-master.tar.gz |
Imported from /home/lorry/working-area/delta_cvs-tarball/cvs-1.12.13.tar.bz2.HEADcvs-1.12.13master
Diffstat (limited to 'os2/getpass.c')
-rw-r--r-- | os2/getpass.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/os2/getpass.c b/os2/getpass.c new file mode 100644 index 0000000..e9ceb22 --- /dev/null +++ b/os2/getpass.c @@ -0,0 +1,63 @@ +#include <stdio.h> +#include <string.h> +#include "cvs.h" +#include "os2inc.h" + +/* Only define this if you're testing and want to compile this file + standalone. */ +/* #define DIAGNOSTIC */ + +/* Turn off keyboard echo. Does not check error returns. */ +static void +EchoOff (void) +{ + KBDINFO KbdInfo; + + KbdGetStatus (&KbdInfo, 0); + KbdInfo.fsMask = (KbdInfo.fsMask & ~KEYBOARD_ECHO_ON) | KEYBOARD_ECHO_OFF; + KbdSetStatus (&KbdInfo, 0); +} + +/* Turn on keyboard echo. Does not check error returns. */ +static void +EchoOn( void ) +{ + KBDINFO KbdInfo; + + KbdGetStatus (&KbdInfo, 0); + KbdInfo.fsMask = (KbdInfo.fsMask & ~KEYBOARD_ECHO_OFF) | KEYBOARD_ECHO_ON; + KbdSetStatus (&KbdInfo, 0); +} + +char * +getpass (char *prompt) +{ + static char Buf[80]; + STRINGINBUF StringInBuf; + + printf ("%s", prompt); + fflush (stdout); + + EchoOff (); + + StringInBuf.cb = sizeof (Buf) - 1; + StringInBuf.cchIn = 0; + KbdStringIn ((PSZ) Buf, &StringInBuf, IO_WAIT, 0); + Buf[StringInBuf.cchIn] = '\0'; + + EchoOn (); + + return Buf; +} + + +#ifdef DIAGNOSTIC +main() +{ + char *s; + s = getpass ("Input password (no echo): "); + printf ("String was \"%s\"\n", s); + fflush (stdout); +} +#endif /* DIAGNOSTIC */ + |