diff options
author | Ron Yorston <rmy@pobox.com> | 2020-12-07 08:40:25 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2020-12-07 08:45:29 +0000 |
commit | 26b641cde2e1bb2ed95683afa94b31ba0207339d (patch) | |
tree | f1caf6cdf0da02da2375a7d2c0fed11a00e4888e | |
parent | fd774ee45b592977ebd7cb06cb0049d69219a530 (diff) | |
download | busybox-w32-26b641cde2e1bb2ed95683afa94b31ba0207339d.tar.gz busybox-w32-26b641cde2e1bb2ed95683afa94b31ba0207339d.tar.bz2 busybox-w32-26b641cde2e1bb2ed95683afa94b31ba0207339d.zip |
winansi: intercept calls to fputc(3)
Perform code page translation for fputc(3). It's only used in a
few places but is needed to fix things like:
$ echo € | dos2unix
Ç
$ paste -d € file1 file2
1Ç2
Unfortunately it breaks the inventive use of dos2unix in GitHub
issue #203.
-rw-r--r-- | include/mingw.h | 2 | ||||
-rw-r--r-- | win32/winansi.c | 20 |
2 files changed, 21 insertions, 1 deletions
diff --git a/include/mingw.h b/include/mingw.h index d70bc26e6..8af2e3938 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
@@ -152,6 +152,7 @@ int winansi_putchar(int c); | |||
152 | int winansi_puts(const char *s); | 152 | int winansi_puts(const char *s); |
153 | size_t winansi_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); | 153 | size_t winansi_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); |
154 | int winansi_fputs(const char *str, FILE *stream); | 154 | int winansi_fputs(const char *str, FILE *stream); |
155 | int winansi_fputc(int c, FILE *stream); | ||
155 | int winansi_vsnprintf(char *buf, size_t size, const char *format, va_list list); | 156 | int winansi_vsnprintf(char *buf, size_t size, const char *format, va_list list); |
156 | int winansi_vfprintf(FILE *stream, const char *format, va_list list); | 157 | int winansi_vfprintf(FILE *stream, const char *format, va_list list); |
157 | int winansi_printf(const char *format, ...) __attribute__((format (printf, 1, 2))); | 158 | int winansi_printf(const char *format, ...) __attribute__((format (printf, 1, 2))); |
@@ -163,6 +164,7 @@ int winansi_getc(FILE *stream); | |||
163 | #define puts winansi_puts | 164 | #define puts winansi_puts |
164 | #define fwrite winansi_fwrite | 165 | #define fwrite winansi_fwrite |
165 | #define fputs winansi_fputs | 166 | #define fputs winansi_fputs |
167 | #define fputc winansi_fputc | ||
166 | #if !defined(__USE_MINGW_ANSI_STDIO) || !__USE_MINGW_ANSI_STDIO | 168 | #if !defined(__USE_MINGW_ANSI_STDIO) || !__USE_MINGW_ANSI_STDIO |
167 | #define vsnprintf(buf, size, ...) winansi_vsnprintf(buf, size, __VA_ARGS__) | 169 | #define vsnprintf(buf, size, ...) winansi_vsnprintf(buf, size, __VA_ARGS__) |
168 | #endif | 170 | #endif |
diff --git a/win32/winansi.c b/win32/winansi.c index 8ec75a4e4..3767e7534 100644 --- a/win32/winansi.c +++ b/win32/winansi.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #undef printf | 14 | #undef printf |
15 | #undef fprintf | 15 | #undef fprintf |
16 | #undef fputs | 16 | #undef fputs |
17 | #undef fputc | ||
17 | #undef putchar | 18 | #undef putchar |
18 | #undef fwrite | 19 | #undef fwrite |
19 | #undef puts | 20 | #undef puts |
@@ -635,7 +636,7 @@ int winansi_putchar(int c) | |||
635 | return putchar(c); | 636 | return putchar(c); |
636 | 637 | ||
637 | CharToOemBuff(s, s, 1); | 638 | CharToOemBuff(s, s, 1); |
638 | return putchar(t) == EOF ? EOF : c; | 639 | return putchar(t) == EOF ? EOF : (unsigned char)c; |
639 | } | 640 | } |
640 | 641 | ||
641 | int winansi_puts(const char *s) | 642 | int winansi_puts(const char *s) |
@@ -720,6 +721,23 @@ int winansi_fputs(const char *str, FILE *stream) | |||
720 | return ansi_emulate(str, stream) == EOF ? EOF : 0; | 721 | return ansi_emulate(str, stream) == EOF ? EOF : 0; |
721 | } | 722 | } |
722 | 723 | ||
724 | int winansi_fputc(int c, FILE *stream) | ||
725 | { | ||
726 | int ret; | ||
727 | char t = c; | ||
728 | char *s = &t; | ||
729 | |||
730 | if (!is_console(fileno(stream))) { | ||
731 | SetLastError(0); | ||
732 | if ((ret=fputc(c, stream)) == EOF) | ||
733 | check_pipe(stream); | ||
734 | return ret; | ||
735 | } | ||
736 | |||
737 | CharToOemBuff(s, s, 1); | ||
738 | return fputc(t, stream) == EOF ? EOF : (unsigned char )c; | ||
739 | } | ||
740 | |||
723 | #if !defined(__USE_MINGW_ANSI_STDIO) || !__USE_MINGW_ANSI_STDIO | 741 | #if !defined(__USE_MINGW_ANSI_STDIO) || !__USE_MINGW_ANSI_STDIO |
724 | /* | 742 | /* |
725 | * Prior to Windows 10 vsnprintf was incompatible with the C99 standard. | 743 | * Prior to Windows 10 vsnprintf was incompatible with the C99 standard. |