From 9e26feebb1f6752fa21f4680a744cdc688366be5 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Mon, 23 Apr 2012 10:36:01 +0100 Subject: win32: implement ioctl --- include/mingw.h | 2 +- libbb/xfuncs.c | 4 ---- win32/Kbuild | 1 + win32/ioctl.c | 24 ++++++++++++++++++++++++ win32/winansi.c | 2 +- 5 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 win32/ioctl.c diff --git a/include/mingw.h b/include/mingw.h index b81a6e180..66296cfc8 100644 --- a/include/mingw.h +++ b/include/mingw.h @@ -183,7 +183,7 @@ void unsetenv(const char *env); #define TIOCGWINSZ 0x5413 -NOIMPL(ioctl,int fd UNUSED_PARAM, int code UNUSED_PARAM,...); +int ioctl(int fd, int code, ...); /* * sys/socket.h diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index e657820f3..23f27516f 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c @@ -262,11 +262,7 @@ int FAST_FUNC get_terminal_width_height(int fd, unsigned *width, unsigned *heigh win.ws_col = 0; /* I've seen ioctl returning 0, but row/col is (still?) 0. * We treat that as an error too. */ -#if !ENABLE_PLATFORM_MINGW32 err = ioctl(fd, TIOCGWINSZ, &win) != 0 || win.ws_row == 0; -#else - err = winansi_get_terminal_width_height(&win) == 0; -#endif if (height) *height = wh_helper(win.ws_row, 24, "LINES", &err); if (width) diff --git a/win32/Kbuild b/win32/Kbuild index 42df86692..ceede0c67 100644 --- a/win32/Kbuild +++ b/win32/Kbuild @@ -6,6 +6,7 @@ lib-y:= lib-$(CONFIG_PLATFORM_MINGW32) += env.o lib-$(CONFIG_PLATFORM_MINGW32) += fnmatch.o +lib-$(CONFIG_PLATFORM_MINGW32) += ioctl.o lib-$(CONFIG_PLATFORM_MINGW32) += mingw.o lib-$(CONFIG_PLATFORM_MINGW32) += process.o lib-$(CONFIG_PLATFORM_MINGW32) += regex.o diff --git a/win32/ioctl.c b/win32/ioctl.c new file mode 100644 index 000000000..73ceeedec --- /dev/null +++ b/win32/ioctl.c @@ -0,0 +1,24 @@ +#include "libbb.h" + +int ioctl(int fd UNUSED_PARAM, int code, ...) +{ + va_list ap; + void *arg; + int ret = -1; + + va_start(ap, code); + + switch (code) { + case TIOCGWINSZ: + arg = va_arg(ap, void *); + ret = winansi_get_terminal_width_height((struct winsize *)arg); + break; + default: + ret = -1; + errno = EINVAL; + break; + } + + va_end(ap); + return ret; +} diff --git a/win32/winansi.c b/win32/winansi.c index 7730fd006..c923bde56 100644 --- a/win32/winansi.c +++ b/win32/winansi.c @@ -432,5 +432,5 @@ int winansi_get_terminal_width_height(struct winsize *win) win->ws_col = sbi.srWindow.Right - sbi.srWindow.Left + 1; } - return ret; + return ret ? 0 : -1; } -- cgit v1.2.3-55-g6feb