Last change
on this file since 26651 was 26651, checked in by davidb, 11 years ago |
Inclusion of open-source code that implements the getpass() algorithm to make Greenstone code more portable. Motivation for adding this in came from work with cross-compiling (using mingw under Ubuntu for generating Windows native binaries).
|
File size:
714 bytes
|
Line | |
---|
1 | /*
|
---|
2 | * UNIX getpass function.
|
---|
3 | */
|
---|
4 | # include <stdio.h>
|
---|
5 | char *getpass (char *prompt)
|
---|
6 | {
|
---|
7 | static char pass[1024];
|
---|
8 | char *p = pass;
|
---|
9 | int k;
|
---|
10 |
|
---|
11 | if (prompt) {
|
---|
12 | while (*prompt) {
|
---|
13 | putc (*prompt++, stderr);
|
---|
14 | }
|
---|
15 | }
|
---|
16 |
|
---|
17 | do {
|
---|
18 | k = getch ();
|
---|
19 | if (p < pass + 1023) {
|
---|
20 | switch (k) {
|
---|
21 | case 0x04:
|
---|
22 | case 0x0D:
|
---|
23 | break;
|
---|
24 | case 0x08:
|
---|
25 | if (p > pass) p--;
|
---|
26 | break;
|
---|
27 | case 0xE0:
|
---|
28 | case 0x00:
|
---|
29 | getch ();
|
---|
30 | break;
|
---|
31 | default:
|
---|
32 | *p++ = k;
|
---|
33 | break;
|
---|
34 | }
|
---|
35 | }
|
---|
36 | }
|
---|
37 | while (k != 0x0D && k != 0x04);
|
---|
38 | *p = 0x00;
|
---|
39 | if (k == 0x0D) {
|
---|
40 | putc (0x0D, stderr);
|
---|
41 | putc (0x0A, stderr);
|
---|
42 | }
|
---|
43 | return pass;
|
---|
44 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.