diff options
-rw-r--r-- | libbb/Kbuild | 2 | ||||
-rw-r--r-- | win32/termios.c | 27 |
2 files changed, 27 insertions, 2 deletions
diff --git a/libbb/Kbuild b/libbb/Kbuild index eb3cd5039..a8a1da1f9 100644 --- a/libbb/Kbuild +++ b/libbb/Kbuild | |||
@@ -74,7 +74,6 @@ lib-y += procps.o | |||
74 | lib-y += progress.o | 74 | lib-y += progress.o |
75 | lib-y += ptr_to_globals.o | 75 | lib-y += ptr_to_globals.o |
76 | lib-y += read.o | 76 | lib-y += read.o |
77 | lib-y += read_key.o | ||
78 | lib-y += recursive_action.o | 77 | lib-y += recursive_action.o |
79 | lib-y += remove_file.o | 78 | lib-y += remove_file.o |
80 | lib-y += run_shell.o | 79 | lib-y += run_shell.o |
@@ -115,6 +114,7 @@ lib-$(CONFIG_PLATFORM_POSIX) += kernel_version.o | |||
115 | lib-$(CONFIG_PLATFORM_POSIX) += login.o | 114 | lib-$(CONFIG_PLATFORM_POSIX) += login.o |
116 | lib-$(CONFIG_PLATFORM_POSIX) += makedev.o | 115 | lib-$(CONFIG_PLATFORM_POSIX) += makedev.o |
117 | lib-$(CONFIG_PLATFORM_POSIX) += match_fstype.o | 116 | lib-$(CONFIG_PLATFORM_POSIX) += match_fstype.o |
117 | lib-$(CONFIG_PLATFORM_POSIX) += read_key.o | ||
118 | lib-$(CONFIG_PLATFORM_POSIX) += safe_gethostname.o | 118 | lib-$(CONFIG_PLATFORM_POSIX) += safe_gethostname.o |
119 | lib-$(CONFIG_PLATFORM_POSIX) += signals.o | 119 | lib-$(CONFIG_PLATFORM_POSIX) += signals.o |
120 | lib-$(CONFIG_PLATFORM_POSIX) += udp_io.o | 120 | lib-$(CONFIG_PLATFORM_POSIX) += udp_io.o |
diff --git a/win32/termios.c b/win32/termios.c index 0aba48546..6d85ff98e 100644 --- a/win32/termios.c +++ b/win32/termios.c | |||
@@ -1,4 +1,4 @@ | |||
1 | #include "busybox.h" | 1 | #include "libbb.h" |
2 | 2 | ||
3 | int tcsetattr(int fd UNUSED_PARAM, int mode UNUSED_PARAM, const struct termios *t UNUSED_PARAM) | 3 | int tcsetattr(int fd UNUSED_PARAM, int mode UNUSED_PARAM, const struct termios *t UNUSED_PARAM) |
4 | { | 4 | { |
@@ -9,3 +9,28 @@ int tcgetattr(int fd UNUSED_PARAM, struct termios *t UNUSED_PARAM) | |||
9 | { | 9 | { |
10 | return -1; | 10 | return -1; |
11 | } | 11 | } |
12 | |||
13 | int64_t FAST_FUNC read_key(int fd, char *buf, int timeout UNUSED_PARAM) | ||
14 | { | ||
15 | static int initialized = 0; | ||
16 | HANDLE cin = GetStdHandle(STD_INPUT_HANDLE); | ||
17 | INPUT_RECORD record; | ||
18 | DWORD nevent_out; | ||
19 | |||
20 | if (fd != 0) | ||
21 | bb_error_msg_and_die("read_key only works on stdin"); | ||
22 | if (cin == INVALID_HANDLE_VALUE) | ||
23 | return -1; | ||
24 | if (!initialized) { | ||
25 | SetConsoleMode(cin, ENABLE_ECHO_INPUT); | ||
26 | initialized = 1; | ||
27 | } | ||
28 | |||
29 | while (1) { | ||
30 | if (!ReadConsoleInput(cin, &record, 1, &nevent_out)) | ||
31 | return -1; | ||
32 | if (record.EventType != KEY_EVENT || !record.Event.KeyEvent.bKeyDown) | ||
33 | continue; | ||
34 | return record.Event.KeyEvent.uChar.AsciiChar; | ||
35 | } | ||
36 | } | ||