aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2023-03-05 12:33:01 +0000
committerRon Yorston <rmy@pobox.com>2023-03-05 12:33:01 +0000
commit9aef4d4d298987437e33bf25bcddd16175148d45 (patch)
tree172ada18bda876ec9041c74a3199d8a475e0fb3b
parent4020c7689c3f640e8a56edd1a1491403112857ec (diff)
downloadbusybox-w32-9aef4d4d298987437e33bf25bcddd16175148d45.tar.gz
busybox-w32-9aef4d4d298987437e33bf25bcddd16175148d45.tar.bz2
busybox-w32-9aef4d4d298987437e33bf25bcddd16175148d45.zip
win32: enable Unix read_key() for virtual terminal
Until now busybox-w32 has used a native Windows implementation of read_key(). Build the upstream Unix implementation and use it instead of the native version when virtual terminal input mode is enabled.
-rw-r--r--include/libbb.h5
-rw-r--r--libbb/Kbuild.src2
-rw-r--r--libbb/read_key.c4
-rw-r--r--win32/termios.c5
4 files changed, 11 insertions, 5 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 4197a5e83..c1d4d11c1 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1976,11 +1976,10 @@ enum {
1976 */ 1976 */
1977int64_t read_key(int fd, char *buffer, int timeout) FAST_FUNC; 1977int64_t read_key(int fd, char *buffer, int timeout) FAST_FUNC;
1978#if ENABLE_PLATFORM_MINGW32 1978#if ENABLE_PLATFORM_MINGW32
1979#define safe_read_key(f, b, t) read_key(f, b, t) 1979int64_t unix_read_key(int fd, char *buffer, int timeout) FAST_FUNC;
1980#else 1980#endif
1981/* This version loops on EINTR: */ 1981/* This version loops on EINTR: */
1982int64_t safe_read_key(int fd, char *buffer, int timeout) FAST_FUNC; 1982int64_t safe_read_key(int fd, char *buffer, int timeout) FAST_FUNC;
1983#endif
1984void read_key_ungets(char *buffer, const char *str, unsigned len) FAST_FUNC; 1983void read_key_ungets(char *buffer, const char *str, unsigned len) FAST_FUNC;
1985 1984
1986 1985
diff --git a/libbb/Kbuild.src b/libbb/Kbuild.src
index 191984c9d..425bfe1c6 100644
--- a/libbb/Kbuild.src
+++ b/libbb/Kbuild.src
@@ -64,6 +64,7 @@ lib-y += process_escape_sequence.o
64lib-y += procps.o 64lib-y += procps.o
65lib-y += ptr_to_globals.o 65lib-y += ptr_to_globals.o
66lib-y += read.o 66lib-y += read.o
67lib-y += read_key.o
67lib-y += read_printf.o 68lib-y += read_printf.o
68lib-y += recursive_action.o 69lib-y += recursive_action.o
69lib-y += remove_file.o 70lib-y += remove_file.o
@@ -114,7 +115,6 @@ lib-$(CONFIG_PLATFORM_POSIX) += perror_nomsg.o
114lib-$(CONFIG_PLATFORM_POSIX) += pidfile.o 115lib-$(CONFIG_PLATFORM_POSIX) += pidfile.o
115lib-$(CONFIG_PLATFORM_POSIX) += print_flags.o 116lib-$(CONFIG_PLATFORM_POSIX) += print_flags.o
116lib-$(CONFIG_PLATFORM_POSIX) += progress.o 117lib-$(CONFIG_PLATFORM_POSIX) += progress.o
117lib-$(CONFIG_PLATFORM_POSIX) += read_key.o
118lib-$(CONFIG_PLATFORM_POSIX) += setup_environment.o 118lib-$(CONFIG_PLATFORM_POSIX) += setup_environment.o
119lib-$(CONFIG_PLATFORM_POSIX) += signals.o 119lib-$(CONFIG_PLATFORM_POSIX) += signals.o
120lib-$(CONFIG_PLATFORM_POSIX) += speed_table.o 120lib-$(CONFIG_PLATFORM_POSIX) += speed_table.o
diff --git a/libbb/read_key.c b/libbb/read_key.c
index cf8ed411e..c34770028 100644
--- a/libbb/read_key.c
+++ b/libbb/read_key.c
@@ -9,7 +9,11 @@
9 */ 9 */
10#include "libbb.h" 10#include "libbb.h"
11 11
12#if ENABLE_PLATFORM_MINGW32
13int64_t FAST_FUNC unix_read_key(int fd, char *buffer, int timeout)
14#else
12int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout) 15int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout)
16#endif
13{ 17{
14 struct pollfd pfd; 18 struct pollfd pfd;
15 const char *seq; 19 const char *seq;
diff --git a/win32/termios.c b/win32/termios.c
index 4b3588826..20ec4dcc5 100644
--- a/win32/termios.c
+++ b/win32/termios.c
@@ -28,7 +28,7 @@ int tcgetattr(int fd, struct termios *t)
28 return 0; 28 return 0;
29} 29}
30 30
31int64_t FAST_FUNC read_key(int fd, char *buf UNUSED_PARAM, int timeout) 31int64_t FAST_FUNC read_key(int fd, char *buf, int timeout)
32{ 32{
33 HANDLE cin = GetStdHandle(STD_INPUT_HANDLE); 33 HANDLE cin = GetStdHandle(STD_INPUT_HANDLE);
34 INPUT_RECORD record; 34 INPUT_RECORD record;
@@ -41,6 +41,9 @@ int64_t FAST_FUNC read_key(int fd, char *buf UNUSED_PARAM, int timeout)
41 DWORD alt_pressed = FALSE; 41 DWORD alt_pressed = FALSE;
42 DWORD state; 42 DWORD state;
43 43
44 if (terminal_mode(FALSE) & VT_INPUT)
45 return unix_read_key(fd, buf, timeout);
46
44 if (fd != 0) 47 if (fd != 0)
45 bb_error_msg_and_die("read_key only works on stdin"); 48 bb_error_msg_and_die("read_key only works on stdin");
46 if (cin == INVALID_HANDLE_VALUE) 49 if (cin == INVALID_HANDLE_VALUE)