diff options
author | Ron Yorston <rmy@pobox.com> | 2018-04-03 11:13:10 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2018-04-03 12:29:01 +0100 |
commit | 32f8569a99b948e810266608dd6e3bf9de611df5 (patch) | |
tree | ec891c62ed84879a99de960365cc4ba935e02c90 /win32 | |
parent | 4d8668e4b6bac0d7902dd677d540c700817b094b (diff) | |
download | busybox-w32-32f8569a99b948e810266608dd6e3bf9de611df5.tar.gz busybox-w32-32f8569a99b948e810266608dd6e3bf9de611df5.tar.bz2 busybox-w32-32f8569a99b948e810266608dd6e3bf9de611df5.zip |
win32: improvements to get_terminal_width_height
- move winansi_get_terminal_width_height from winansi.c to ioctl.c,
the only caller;
- check both stdout and stderr for a connection to a console;
- omit unnecessary code in get_terminal_width_height (because the
WIN32 implementation ignores the file descriptor).
Diffstat (limited to 'win32')
-rw-r--r-- | win32/ioctl.c | 24 | ||||
-rw-r--r-- | win32/winansi.c | 17 |
2 files changed, 23 insertions, 18 deletions
diff --git a/win32/ioctl.c b/win32/ioctl.c index 73ceeedec..93f9f504d 100644 --- a/win32/ioctl.c +++ b/win32/ioctl.c | |||
@@ -1,5 +1,27 @@ | |||
1 | #include "libbb.h" | 1 | #include "libbb.h" |
2 | 2 | ||
3 | static int mingw_get_terminal_width_height(struct winsize *win) | ||
4 | { | ||
5 | int fd; | ||
6 | HANDLE handle; | ||
7 | CONSOLE_SCREEN_BUFFER_INFO sbi; | ||
8 | |||
9 | win->ws_row = 0; | ||
10 | win->ws_col = 0; | ||
11 | |||
12 | for (fd=STDOUT_FILENO; fd<=STDERR_FILENO; ++fd) { | ||
13 | handle = (HANDLE)_get_osfhandle(fd); | ||
14 | if (handle != INVALID_HANDLE_VALUE && | ||
15 | GetConsoleScreenBufferInfo(handle, &sbi) != 0) { | ||
16 | win->ws_row = sbi.srWindow.Bottom - sbi.srWindow.Top + 1; | ||
17 | win->ws_col = sbi.srWindow.Right - sbi.srWindow.Left + 1; | ||
18 | return 0; | ||
19 | } | ||
20 | } | ||
21 | |||
22 | return -1; | ||
23 | } | ||
24 | |||
3 | int ioctl(int fd UNUSED_PARAM, int code, ...) | 25 | int ioctl(int fd UNUSED_PARAM, int code, ...) |
4 | { | 26 | { |
5 | va_list ap; | 27 | va_list ap; |
@@ -11,7 +33,7 @@ int ioctl(int fd UNUSED_PARAM, int code, ...) | |||
11 | switch (code) { | 33 | switch (code) { |
12 | case TIOCGWINSZ: | 34 | case TIOCGWINSZ: |
13 | arg = va_arg(ap, void *); | 35 | arg = va_arg(ap, void *); |
14 | ret = winansi_get_terminal_width_height((struct winsize *)arg); | 36 | ret = mingw_get_terminal_width_height((struct winsize *)arg); |
15 | break; | 37 | break; |
16 | default: | 38 | default: |
17 | ret = -1; | 39 | ret = -1; |
diff --git a/win32/winansi.c b/win32/winansi.c index ad6016ddc..a8f5dba79 100644 --- a/win32/winansi.c +++ b/win32/winansi.c | |||
@@ -596,23 +596,6 @@ int winansi_printf(const char *format, ...) | |||
596 | return rv; | 596 | return rv; |
597 | } | 597 | } |
598 | 598 | ||
599 | int winansi_get_terminal_width_height(struct winsize *win) | ||
600 | { | ||
601 | BOOL ret; | ||
602 | CONSOLE_SCREEN_BUFFER_INFO sbi; | ||
603 | |||
604 | init(); | ||
605 | |||
606 | win->ws_row = 0; | ||
607 | win->ws_col = 0; | ||
608 | if ((ret=GetConsoleScreenBufferInfo(console, &sbi)) != 0) { | ||
609 | win->ws_row = sbi.srWindow.Bottom - sbi.srWindow.Top + 1; | ||
610 | win->ws_col = sbi.srWindow.Right - sbi.srWindow.Left + 1; | ||
611 | } | ||
612 | |||
613 | return ret ? 0 : -1; | ||
614 | } | ||
615 | |||
616 | static int ansi_emulate_write(int fd, const void *buf, size_t count) | 599 | static int ansi_emulate_write(int fd, const void *buf, size_t count) |
617 | { | 600 | { |
618 | int rv = 0, i; | 601 | int rv = 0, i; |