aboutsummaryrefslogtreecommitdiff
path: root/win32/ioctl.c
diff options
context:
space:
mode:
Diffstat (limited to 'win32/ioctl.c')
-rw-r--r--win32/ioctl.c24
1 files changed, 23 insertions, 1 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
3static 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
3int ioctl(int fd UNUSED_PARAM, int code, ...) 25int 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;