xref: /openbsd-src/gnu/usr.bin/cvs/os2/getpass.c (revision 461cc63e7458ce60db55037c1a7656349538b52f)
1 #include <stdio.h>
2 #include <string.h>
3 #include "cvs.h"
4 #include "os2inc.h"
5 
6 /* Only define this if you're testing and want to compile this file
7    standalone. */
8 /* #define DIAGNOSTIC */
9 
10 /* Turn off keyboard echo.  Does not check error returns. */
11 static void
EchoOff(void)12 EchoOff (void)
13 {
14   KBDINFO KbdInfo;
15 
16   KbdGetStatus (&KbdInfo, 0);
17   KbdInfo.fsMask = (KbdInfo.fsMask & ~KEYBOARD_ECHO_ON) | KEYBOARD_ECHO_OFF;
18   KbdSetStatus (&KbdInfo, 0);
19 }
20 
21 /* Turn on keyboard echo.  Does not check error returns. */
22 static void
EchoOn(void)23 EchoOn( void )
24 {
25   KBDINFO KbdInfo;
26 
27   KbdGetStatus (&KbdInfo, 0);
28   KbdInfo.fsMask = (KbdInfo.fsMask & ~KEYBOARD_ECHO_OFF) | KEYBOARD_ECHO_ON;
29   KbdSetStatus (&KbdInfo, 0);
30 }
31 
32 char *
getpass(char * prompt)33 getpass (char *prompt)
34 {
35   static char Buf[80];
36   STRINGINBUF StringInBuf;
37 
38   printf ("%s", prompt);
39   fflush (stdout);
40 
41   EchoOff ();
42 
43   StringInBuf.cb = sizeof (Buf) - 1;
44   StringInBuf.cchIn = 0;
45   KbdStringIn ((PSZ) Buf, &StringInBuf, IO_WAIT, 0);
46   Buf[StringInBuf.cchIn] = '\0';
47 
48   EchoOn ();
49 
50   return Buf;
51 }
52 
53 
54 #ifdef DIAGNOSTIC
main()55 main()
56 {
57   char *s;
58   s = getpass ("Input password (no echo): ");
59   printf ("String was \"%s\"\n", s);
60   fflush (stdout);
61 }
62 #endif /* DIAGNOSTIC */
63 
64