aboutsummaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2020-12-07 08:40:25 +0000
committerRon Yorston <rmy@pobox.com>2020-12-07 08:45:29 +0000
commit26b641cde2e1bb2ed95683afa94b31ba0207339d (patch)
treef1caf6cdf0da02da2375a7d2c0fed11a00e4888e /win32
parentfd774ee45b592977ebd7cb06cb0049d69219a530 (diff)
downloadbusybox-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.
Diffstat (limited to 'win32')
-rw-r--r--win32/winansi.c20
1 files changed, 19 insertions, 1 deletions
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
641int winansi_puts(const char *s) 642int 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
724int 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.