From 26b641cde2e1bb2ed95683afa94b31ba0207339d Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Mon, 7 Dec 2020 08:40:25 +0000 Subject: winansi: intercept calls to fputc(3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- win32/winansi.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'win32') 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 @@ #undef printf #undef fprintf #undef fputs +#undef fputc #undef putchar #undef fwrite #undef puts @@ -635,7 +636,7 @@ int winansi_putchar(int c) return putchar(c); CharToOemBuff(s, s, 1); - return putchar(t) == EOF ? EOF : c; + return putchar(t) == EOF ? EOF : (unsigned char)c; } int winansi_puts(const char *s) @@ -720,6 +721,23 @@ int winansi_fputs(const char *str, FILE *stream) return ansi_emulate(str, stream) == EOF ? EOF : 0; } +int winansi_fputc(int c, FILE *stream) +{ + int ret; + char t = c; + char *s = &t; + + if (!is_console(fileno(stream))) { + SetLastError(0); + if ((ret=fputc(c, stream)) == EOF) + check_pipe(stream); + return ret; + } + + CharToOemBuff(s, s, 1); + return fputc(t, stream) == EOF ? EOF : (unsigned char )c; +} + #if !defined(__USE_MINGW_ANSI_STDIO) || !__USE_MINGW_ANSI_STDIO /* * Prior to Windows 10 vsnprintf was incompatible with the C99 standard. -- cgit v1.2.3-55-g6feb