aboutsummaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
Diffstat (limited to 'win32')
-rw-r--r--win32/ioctl.c4
-rw-r--r--win32/termios.c43
-rw-r--r--win32/termios.h17
-rw-r--r--win32/winansi.c17
4 files changed, 77 insertions, 4 deletions
diff --git a/win32/ioctl.c b/win32/ioctl.c
index 73ceeedec..f3657966d 100644
--- a/win32/ioctl.c
+++ b/win32/ioctl.c
@@ -13,6 +13,10 @@ int ioctl(int fd UNUSED_PARAM, int code, ...)
13 arg = va_arg(ap, void *); 13 arg = va_arg(ap, void *);
14 ret = winansi_get_terminal_width_height((struct winsize *)arg); 14 ret = winansi_get_terminal_width_height((struct winsize *)arg);
15 break; 15 break;
16 case TIOCSWINSZ:
17 arg = va_arg(ap, void *);
18 ret = winansi_set_terminal_width_height((struct winsize *)arg);
19 break;
16 default: 20 default:
17 ret = -1; 21 ret = -1;
18 errno = EINVAL; 22 errno = EINVAL;
diff --git a/win32/termios.c b/win32/termios.c
index 658af4a26..108a746ef 100644
--- a/win32/termios.c
+++ b/win32/termios.c
@@ -1,13 +1,26 @@
1#include "libbb.h" 1#include "libbb.h"
2 2
3int tcsetattr(int fd UNUSED_PARAM, int mode UNUSED_PARAM, const struct termios *t UNUSED_PARAM) 3static struct termios dummy = {
4 0, /* c_iflag */
5 0, /* c_oflag */
6 0, /* c_cflag */
7 0, /* c_lflag */
8 '\0', /* c_line */
9 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", /* c_cc[NCCS] */
10 B9600, /* c_ispeed */
11 B9600 /* c_ospeed */
12};
13
14int tcsetattr(int fd UNUSED_PARAM, int mode UNUSED_PARAM, const struct termios *t)
4{ 15{
5 return -1; 16 dummy = *t;
17 return 0;
6} 18}
7 19
8int tcgetattr(int fd UNUSED_PARAM, struct termios *t UNUSED_PARAM) 20int tcgetattr(int fd UNUSED_PARAM, struct termios *t)
9{ 21{
10 return -1; 22 *t = dummy;
23 return 0;
11} 24}
12 25
13int64_t FAST_FUNC read_key(int fd, char *buf UNUSED_PARAM, int timeout) 26int64_t FAST_FUNC read_key(int fd, char *buf UNUSED_PARAM, int timeout)
@@ -81,3 +94,25 @@ int64_t FAST_FUNC read_key(int fd, char *buf UNUSED_PARAM, int timeout)
81 SetConsoleMode(cin, mode); 94 SetConsoleMode(cin, mode);
82 return ret; 95 return ret;
83} 96}
97
98speed_t cfgetispeed(const struct termios *termios_p)
99{
100 return termios_p->c_ispeed;
101}
102
103speed_t cfgetospeed(const struct termios *termios_p)
104{
105 return termios_p->c_ospeed;
106}
107
108int cfsetispeed(struct termios *termios_p, speed_t speed)
109{
110 termios_p->c_ispeed = speed;
111 return 0;
112}
113
114int cfsetospeed(struct termios *termios_p, speed_t speed)
115{
116 termios_p->c_ospeed = speed;
117 return 0;
118}
diff --git a/win32/termios.h b/win32/termios.h
index 011a37eb9..9255e0141 100644
--- a/win32/termios.h
+++ b/win32/termios.h
@@ -100,6 +100,18 @@
100#define B2400 0000013 100#define B2400 0000013
101#define B4800 0000014 101#define B4800 0000014
102#define B9600 0000015 102#define B9600 0000015
103#define CSIZE 0000060
104#define CS5 0000000
105#define CS6 0000020
106#define CS7 0000040
107#define CS8 0000060
108#define CSTOPB 0000100
109#define CREAD 0000200
110#define PARENB 0000400
111#define PARODD 0001000
112#define HUPCL 0002000
113#define CLOCAL 0004000
114
103 115
104typedef unsigned char cc_t; 116typedef unsigned char cc_t;
105typedef unsigned int tcflag_t; 117typedef unsigned int tcflag_t;
@@ -127,3 +139,8 @@ struct winsize {
127int tcflush(int fd, int queue_selector); 139int tcflush(int fd, int queue_selector);
128int tcgetattr(int fd, struct termios *t); 140int tcgetattr(int fd, struct termios *t);
129int tcsetattr(int fd, int mode, const struct termios *t); 141int tcsetattr(int fd, int mode, const struct termios *t);
142
143speed_t cfgetispeed(const struct termios *termios_p);
144speed_t cfgetospeed(const struct termios *termios_p);
145int cfsetispeed(struct termios *termios_p, speed_t speed);
146int cfsetospeed(struct termios *termios_p, speed_t speed);
diff --git a/win32/winansi.c b/win32/winansi.c
index c0493c77e..757a3509d 100644
--- a/win32/winansi.c
+++ b/win32/winansi.c
@@ -596,6 +596,23 @@ int winansi_get_terminal_width_height(struct winsize *win)
596 return ret ? 0 : -1; 596 return ret ? 0 : -1;
597} 597}
598 598
599int winansi_set_terminal_width_height(struct winsize *win)
600{
601 BOOL ret;
602 CONSOLE_SCREEN_BUFFER_INFOEX sbi;
603
604 init();
605
606 sbi.cbSize = sizeof(sbi);
607 if ((ret=GetConsoleScreenBufferInfoEx(console, &sbi)) != 0) {
608 sbi.srWindow.Bottom = sbi.srWindow.Top + win->ws_row;
609 sbi.srWindow.Right = sbi.srWindow.Left + win->ws_col;
610 ret = SetConsoleScreenBufferInfoEx(console, &sbi);
611 }
612
613 return ret ? 0 : -1;
614}
615
599static int ansi_emulate_write(int fd, const void *buf, size_t count) 616static int ansi_emulate_write(int fd, const void *buf, size_t count)
600{ 617{
601 int rv = 0, i; 618 int rv = 0, i;