diff options
| author | Ron Yorston <rmy@pobox.com> | 2023-07-07 14:16:41 +0100 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2023-07-07 14:16:41 +0100 |
| commit | 63f2f555277c8a4b2b992367aa26d497931deaeb (patch) | |
| tree | 864b172f5c29370bf6eca8269d8fd9a92d105a0d | |
| parent | 1f1ab4d386c8c91adc2292faaee42fe4909f2822 (diff) | |
| download | busybox-w32-63f2f555277c8a4b2b992367aa26d497931deaeb.tar.gz busybox-w32-63f2f555277c8a4b2b992367aa26d497931deaeb.tar.bz2 busybox-w32-63f2f555277c8a4b2b992367aa26d497931deaeb.zip | |
win32: more console input character conversions
Add wrappers for the following input functions with conversions
for console input. Applications suitable for testing these changes
are appended in brackets.
- getchar (xargs)
- fgetc (tac)
- getline (shuf)
- fgets (rev)
Costs 112-120 bytes.
| -rw-r--r-- | include/mingw.h | 5 | ||||
| -rw-r--r-- | win32/winansi.c | 20 |
2 files changed, 25 insertions, 0 deletions
diff --git a/include/mingw.h b/include/mingw.h index a95bf2e91..f11316205 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
| @@ -172,6 +172,8 @@ int winansi_write(int fd, const void *buf, size_t count); | |||
| 172 | int winansi_read(int fd, void *buf, size_t count); | 172 | int winansi_read(int fd, void *buf, size_t count); |
| 173 | size_t winansi_fread(void *ptr, size_t size, size_t nmemb, FILE *stream); | 173 | size_t winansi_fread(void *ptr, size_t size, size_t nmemb, FILE *stream); |
| 174 | int winansi_getc(FILE *stream); | 174 | int winansi_getc(FILE *stream); |
| 175 | int winansi_getchar(void); | ||
| 176 | char *winansi_fgets(char *s, int size, FILE *stream); | ||
| 175 | 177 | ||
| 176 | #define putchar winansi_putchar | 178 | #define putchar winansi_putchar |
| 177 | #define puts winansi_puts | 179 | #define puts winansi_puts |
| @@ -189,6 +191,9 @@ int winansi_getc(FILE *stream); | |||
| 189 | #define read winansi_read | 191 | #define read winansi_read |
| 190 | #define fread winansi_fread | 192 | #define fread winansi_fread |
| 191 | #define getc winansi_getc | 193 | #define getc winansi_getc |
| 194 | #define fgetc winansi_getc | ||
| 195 | #define getchar winansi_getchar | ||
| 196 | #define fgets winansi_fgets | ||
| 192 | 197 | ||
| 193 | /* | 198 | /* |
| 194 | * stdlib.h | 199 | * stdlib.h |
diff --git a/win32/winansi.c b/win32/winansi.c index ad0d92698..818ab1793 100644 --- a/win32/winansi.c +++ b/win32/winansi.c | |||
| @@ -26,6 +26,7 @@ static BOOL charToConA(LPSTR s); | |||
| 26 | #undef read | 26 | #undef read |
| 27 | #undef fread | 27 | #undef fread |
| 28 | #undef getc | 28 | #undef getc |
| 29 | #undef fgets | ||
| 29 | 30 | ||
| 30 | #define FOREGROUND_ALL (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE) | 31 | #define FOREGROUND_ALL (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE) |
| 31 | #define BACKGROUND_ALL (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE) | 32 | #define BACKGROUND_ALL (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE) |
| @@ -1169,6 +1170,25 @@ int winansi_getc(FILE *stream) | |||
| 1169 | return rv; | 1170 | return rv; |
| 1170 | } | 1171 | } |
| 1171 | 1172 | ||
| 1173 | int winansi_getchar(void) | ||
| 1174 | { | ||
| 1175 | return winansi_getc(stdin); | ||
| 1176 | } | ||
| 1177 | |||
| 1178 | char *winansi_fgets(char *s, int size, FILE *stream) | ||
| 1179 | { | ||
| 1180 | char *rv; | ||
| 1181 | |||
| 1182 | rv = fgets(s, size, stream); | ||
| 1183 | if (!is_console_in(fileno(stream))) | ||
| 1184 | return rv; | ||
| 1185 | |||
| 1186 | if (rv) | ||
| 1187 | conToCharBuffA(s, strlen(s)); | ||
| 1188 | |||
| 1189 | return rv; | ||
| 1190 | } | ||
| 1191 | |||
| 1172 | /* Ensure that isatty(fd) returns 0 for the NUL device */ | 1192 | /* Ensure that isatty(fd) returns 0 for the NUL device */ |
| 1173 | int mingw_isatty(int fd) | 1193 | int mingw_isatty(int fd) |
| 1174 | { | 1194 | { |
