-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.c
43 lines (34 loc) · 799 Bytes
/
input.c
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
#include <stdio.h>
#include <wtypes.h>
#include <wincon.h>
HANDLE hconin = INVALID_HANDLE_VALUE;
DWORD cmode;
void restore_term(void) {
if (hconin == INVALID_HANDLE_VALUE)
return;
SetConsoleMode(hconin, cmode);
CloseHandle(hconin);
hconin = INVALID_HANDLE_VALUE;
}
int disable_echo(void) {
hconin = CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
if (hconin == INVALID_HANDLE_VALUE)
return -1;
GetConsoleMode(hconin, &cmode);
if (!SetConsoleMode(hconin, cmode & (~ENABLE_ECHO_INPUT))) {
CloseHandle(hconin);
hconin = INVALID_HANDLE_VALUE;
return -1;
}
return 0;
}
int main(void) {
char psw[100];
disable_echo();
fgets(psw, 100, stdin);
restore_term();
printf("%s", psw);
return 0;
}