summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/cvs/os2/getpass.c
blob: e9ceb22ce16473a9cb8cbae0cdb4f1760ad70094 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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 */