beosstuff.c
1.17 KB
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
#include <stdio.h>
#include <termios.h>
#define MAX_STRING_LEN 256
char *getpass(const char *prompt)
{
struct termios attr;
static char password[MAX_STRING_LEN];
int n=0;
fputs(prompt, stderr);
fflush(stderr);
if (tcgetattr(STDIN_FILENO, &attr) != 0)
return NULL;
attr.c_lflag &= ~(ECHO);
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &attr) != 0)
return NULL;
while ((password[n] = getchar()) != '\n') {
if (password[n] >= ' ' && password[n] <= '~') {
n++;
} else {
fprintf(stderr,"\n");
fputs(prompt, stderr);
fflush(stderr);
n = 0;
}
}
password[n] = '\0';
printf("\n");
if (n > (MAX_STRING_LEN - 1)) {
password[MAX_STRING_LEN - 1] = '\0';
}
attr.c_lflag |= ECHO;
tcsetattr(STDIN_FILENO, TCSANOW, &attr);
return (char*) &password;
}
int kernelInit(void)
{
return 1;
}
void WaitForKeyboard(void)
{
}