aboutsummaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--win32/glob.c2
-rw-r--r--win32/inet_pton.c1
-rw-r--r--win32/ioctl.c39
-rw-r--r--win32/mingw.c9
-rw-r--r--win32/select.c7
-rw-r--r--win32/strptime.c36
-rw-r--r--win32/termios.c26
-rw-r--r--win32/termios.h29
-rw-r--r--win32/winansi.c2
9 files changed, 107 insertions, 44 deletions
diff --git a/win32/glob.c b/win32/glob.c
index 1cc6483e7..35a1e9a65 100644
--- a/win32/glob.c
+++ b/win32/glob.c
@@ -298,7 +298,7 @@ int glob(const char *restrict pat, int flags, int (*errfunc)(const char *path, i
298 if (append(&tail, pat, strlen(pat), 0)) 298 if (append(&tail, pat, strlen(pat), 0))
299 return GLOB_NOSPACE; 299 return GLOB_NOSPACE;
300 cnt++; 300 cnt++;
301 } else 301 } else if (!error)
302 return GLOB_NOMATCH; 302 return GLOB_NOMATCH;
303 } 303 }
304 304
diff --git a/win32/inet_pton.c b/win32/inet_pton.c
index f229a9355..eec8bd2fe 100644
--- a/win32/inet_pton.c
+++ b/win32/inet_pton.c
@@ -78,6 +78,7 @@ int inet_pton(int af, const char *restrict s, void *restrict a0)
78 if (s[j]!='.' || (i<6 && brk<0)) return 0; 78 if (s[j]!='.' || (i<6 && brk<0)) return 0;
79 need_v4=1; 79 need_v4=1;
80 i++; 80 i++;
81 ip[i&7]=0;
81 break; 82 break;
82 } 83 }
83 s += j+1; 84 s += j+1;
diff --git a/win32/ioctl.c b/win32/ioctl.c
index 93f9f504d..dcb96e783 100644
--- a/win32/ioctl.c
+++ b/win32/ioctl.c
@@ -1,5 +1,6 @@
1#include "libbb.h" 1#include "libbb.h"
2 2
3#if ENABLE_STTY || ENABLE_TTYSIZE
3static int mingw_get_terminal_width_height(struct winsize *win) 4static int mingw_get_terminal_width_height(struct winsize *win)
4{ 5{
5 int fd; 6 int fd;
@@ -21,6 +22,36 @@ static int mingw_get_terminal_width_height(struct winsize *win)
21 22
22 return -1; 23 return -1;
23} 24}
25#endif
26
27#if ENABLE_STTY
28static int mingw_set_terminal_width_height(struct winsize *win)
29{
30 BOOL ret;
31
32 for (int fd = STDOUT_FILENO; fd <= STDERR_FILENO; ++fd) {
33 CONSOLE_SCREEN_BUFFER_INFOEX sbi;
34 HANDLE handle = (HANDLE)_get_osfhandle(fd);
35
36 sbi.cbSize = sizeof(sbi);
37 if (handle != INVALID_HANDLE_VALUE &&
38 (ret=GetConsoleScreenBufferInfoEx(handle, &sbi)) != 0) {
39 if (sbi.dwSize.X != win->ws_col) {
40 sbi.dwSize.X = win->ws_col;
41 }
42 if (sbi.dwSize.Y < win->ws_row) {
43 sbi.dwSize.Y = win->ws_row;
44 }
45 sbi.srWindow.Bottom = sbi.srWindow.Top + win->ws_row;
46 sbi.srWindow.Right = sbi.srWindow.Left + win->ws_col;
47 ret = SetConsoleScreenBufferInfoEx(handle, &sbi);
48 break;
49 }
50 }
51
52 return ret ? 0 : -1;
53}
54#endif
24 55
25int ioctl(int fd UNUSED_PARAM, int code, ...) 56int ioctl(int fd UNUSED_PARAM, int code, ...)
26{ 57{
@@ -31,10 +62,18 @@ int ioctl(int fd UNUSED_PARAM, int code, ...)
31 va_start(ap, code); 62 va_start(ap, code);
32 63
33 switch (code) { 64 switch (code) {
65#if ENABLE_STTY || ENABLE_TTYSIZE
34 case TIOCGWINSZ: 66 case TIOCGWINSZ:
35 arg = va_arg(ap, void *); 67 arg = va_arg(ap, void *);
36 ret = mingw_get_terminal_width_height((struct winsize *)arg); 68 ret = mingw_get_terminal_width_height((struct winsize *)arg);
37 break; 69 break;
70#endif
71#if ENABLE_STTY
72 case TIOCSWINSZ:
73 arg = va_arg(ap, void *);
74 ret = mingw_set_terminal_width_height((struct winsize *)arg);
75 break;
76#endif
38 default: 77 default:
39 ret = -1; 78 ret = -1;
40 errno = EINVAL; 79 errno = EINVAL;
diff --git a/win32/mingw.c b/win32/mingw.c
index cb1f84f30..061e7bac6 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -2560,3 +2560,12 @@ int mingw_shell_execute(SHELLEXECUTEINFO *info)
2560 free(lpath); 2560 free(lpath);
2561 return ret; 2561 return ret;
2562} 2562}
2563
2564#if ENABLE_FEATURE_USE_CNG_API
2565void mingw_die_if_error(NTSTATUS status, const char *function_name) {
2566 if (!NT_SUCCESS(status)) {
2567 bb_error_msg_and_die("call to %s failed: 0x%08lX",
2568 function_name, (unsigned long)status);
2569 }
2570}
2571#endif
diff --git a/win32/select.c b/win32/select.c
index 2be221ac8..46a051cfc 100644
--- a/win32/select.c
+++ b/win32/select.c
@@ -273,8 +273,11 @@ mingw_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds,
273 int i, fd, rc; 273 int i, fd, rc;
274 clock_t tend = 0; 274 clock_t tend = 0;
275 275
276 if (nfds > FD_SETSIZE) 276 if (nfds < 0 || nfds > FD_SETSIZE)
277 nfds = FD_SETSIZE; 277 {
278 errno = EINVAL;
279 return -1;
280 }
278 281
279 if (!timeout) 282 if (!timeout)
280 wait_timeout = INFINITE; 283 wait_timeout = INFINITE;
diff --git a/win32/strptime.c b/win32/strptime.c
index 3205b95a2..c12e96202 100644
--- a/win32/strptime.c
+++ b/win32/strptime.c
@@ -1,23 +1,23 @@
1/* Copyright (C) 2002, 2004-2005, 2007, 2009-2020 Free Software Foundation, 1/* Copyright (C) 2002, 2004-2005, 2007, 2009-2024 Free Software Foundation,
2 Inc. 2 Inc.
3 This file is part of the GNU C Library. 3 This file is part of the GNU C Library.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU Lesser General Public License as
7 the Free Software Foundation; either version 2, or (at your option) 7 published by the Free Software Foundation; either version 2.1 of the
8 any later version. 8 License, or (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This file is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU Lesser General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License along 15 You should have received a copy of the GNU Lesser General Public License
16 with this program; if not, see <https://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 17
18/* 18/*
19 * File from gnulib (https://www.gnu.org/software/gnulib/), processed with 19 * File from gnulib (https://www.gnu.org/software/gnulib/), processed with
20 * coan source -U_LIBC -U_NL_CURRENT -UHAVE_TM_GMTOFF strptime.c 20 * coan source -U_LIBC -U_NL_CURRENT -UHAVE_STRUCT_TM_TM_GMTOFF strptime.c
21 * and lightly edited. 21 * and lightly edited.
22 * 22 *
23 * A form of support for tm_gmtoff was later restored. 23 * A form of support for tm_gmtoff was later restored.
@@ -30,7 +30,7 @@
30#include <ctype.h> 30#include <ctype.h>
31#include <limits.h> 31#include <limits.h>
32#include <string.h> 32#include <string.h>
33#include <stdbool.h> 33#include <strings.h>
34 34
35 35
36enum ptime_locale_status { not, loc, raw }; 36enum ptime_locale_status { not, loc, raw };
@@ -543,23 +543,23 @@ __strptime_internal (const char *rp, const char *fmt, struct tm *tm,
543 543
544 if ((have_uweek || have_wweek) && have_wday) 544 if ((have_uweek || have_wweek) && have_wday)
545 { 545 {
546 int save_wday = tm->tm_wday; 546 int saved_wday = tm->tm_wday;
547 int save_mday = tm->tm_mday; 547 int saved_mday = tm->tm_mday;
548 int save_mon = tm->tm_mon; 548 int saved_mon = tm->tm_mon;
549 int w_offset = have_uweek ? 0 : 1; 549 int w_offset = have_uweek ? 0 : 1;
550 550
551 tm->tm_mday = 1; 551 tm->tm_mday = 1;
552 tm->tm_mon = 0; 552 tm->tm_mon = 0;
553 day_of_the_week (tm); 553 day_of_the_week (tm);
554 if (have_mday) 554 if (have_mday)
555 tm->tm_mday = save_mday; 555 tm->tm_mday = saved_mday;
556 if (have_mon) 556 if (have_mon)
557 tm->tm_mon = save_mon; 557 tm->tm_mon = saved_mon;
558 558
559 if (!have_yday) 559 if (!have_yday)
560 tm->tm_yday = ((7 - (tm->tm_wday - w_offset)) % 7 560 tm->tm_yday = ((7 - (tm->tm_wday - w_offset)) % 7
561 + (week_no - 1) *7 561 + (week_no - 1) *7
562 + save_wday - w_offset); 562 + saved_wday - w_offset);
563 563
564 if (!have_mday || !have_mon) 564 if (!have_mday || !have_mon)
565 { 565 {
@@ -575,7 +575,7 @@ __strptime_internal (const char *rp, const char *fmt, struct tm *tm,
575 - __mon_yday[__isleap(1900 + tm->tm_year)][t_mon - 1] + 1); 575 - __mon_yday[__isleap(1900 + tm->tm_year)][t_mon - 1] + 1);
576 } 576 }
577 577
578 tm->tm_wday = save_wday; 578 tm->tm_wday = saved_wday;
579 } 579 }
580 580
581 return (char *) rp; 581 return (char *) rp;
diff --git a/win32/termios.c b/win32/termios.c
index f18ff7c3b..b94f68f59 100644
--- a/win32/termios.c
+++ b/win32/termios.c
@@ -2,12 +2,10 @@
2 2
3int tcsetattr(int fd, int mode UNUSED_PARAM, const struct termios *t) 3int tcsetattr(int fd, int mode UNUSED_PARAM, const struct termios *t)
4{ 4{
5 if (terminal_mode(FALSE) & VT_INPUT) { 5 HANDLE h = (HANDLE)_get_osfhandle(fd);
6 HANDLE h = (HANDLE)_get_osfhandle(fd); 6 if (!SetConsoleMode(h, t->w_mode)) {
7 if (!SetConsoleMode(h, t->imode)) { 7 errno = err_win_to_posix();
8 errno = err_win_to_posix(); 8 return -1;
9 return -1;
10 }
11 } 9 }
12 10
13 return 0; 11 return 0;
@@ -15,16 +13,20 @@ int tcsetattr(int fd, int mode UNUSED_PARAM, const struct termios *t)
15 13
16int tcgetattr(int fd, struct termios *t) 14int tcgetattr(int fd, struct termios *t)
17{ 15{
18 if (terminal_mode(FALSE) & VT_INPUT) { 16 HANDLE h = (HANDLE)_get_osfhandle(fd);
19 HANDLE h = (HANDLE)_get_osfhandle(fd); 17 if (!GetConsoleMode(h, &t->w_mode)) {
20 if (!GetConsoleMode(h, &t->imode)) { 18 errno = err_win_to_posix();
21 errno = err_win_to_posix(); 19 return -1;
22 return -1;
23 }
24 } 20 }
21
25 t->c_cc[VINTR] = 3; // ctrl-c 22 t->c_cc[VINTR] = 3; // ctrl-c
26 t->c_cc[VEOF] = 4; // ctrl-d 23 t->c_cc[VEOF] = 4; // ctrl-d
27 24
25 if (t->w_mode & ENABLE_ECHO_INPUT)
26 t->c_lflag |= ECHO;
27 else
28 t->c_lflag &= ~ECHO;
29
28 return 0; 30 return 0;
29} 31}
30 32
diff --git a/win32/termios.h b/win32/termios.h
index 8408aa3e3..60c51119b 100644
--- a/win32/termios.h
+++ b/win32/termios.h
@@ -1,23 +1,32 @@
1#ifndef TERMIOS_H 1#ifndef TERMIOS_H
2#define TERMIOS_H 2#define TERMIOS_H
3 3
4#define VINTR 0 4#define ECHO 0x0004
5#define VEOF 1
6 5
7#define TCIFLUSH 0 6#define VINTR 0
8#define TCSAFLUSH 1 7#define VEOF 1
9#define TCSANOW 2 8
10#define TCSADRAIN 3 9#define TCIFLUSH 0
11#define TCSADFLUSH 4 10#define TCSAFLUSH 1
11#define TCSANOW 2
12#define TCSADRAIN 3
13#define TCSADFLUSH 4
14
15#define CSIZE 0
12 16
13typedef unsigned char cc_t; 17typedef unsigned char cc_t;
18typedef unsigned int tcflag_t;
14typedef unsigned int speed_t; 19typedef unsigned int speed_t;
15 20
16#define NCCS 2 21#define NCCS 18
17struct termios { 22struct termios {
23 tcflag_t c_iflag;
24 tcflag_t c_oflag;
25 tcflag_t c_cflag;
26 tcflag_t c_lflag;
27 char c_line;
18 cc_t c_cc[NCCS]; 28 cc_t c_cc[NCCS];
19 unsigned long imode; 29 unsigned long w_mode;
20 unsigned long omode;
21}; 30};
22 31
23struct winsize { 32struct winsize {
diff --git a/win32/winansi.c b/win32/winansi.c
index c7529c453..9736f0568 100644
--- a/win32/winansi.c
+++ b/win32/winansi.c
@@ -160,7 +160,7 @@ int FAST_FUNC terminal_mode(int reset)
160 mode |= VT_INPUT; 160 mode |= VT_INPUT;
161 } 161 }
162 162
163 if (newmode != oldmode) { 163 if (reset && newmode != oldmode) {
164 if (!SetConsoleMode(h, newmode)) { 164 if (!SetConsoleMode(h, newmode)) {
165 if (mode >= 4) 165 if (mode >= 4)
166 mode &= ~VT_INPUT; 166 mode &= ~VT_INPUT;