From 19633819727ac696e51e0e1f5a6e65fd29f5c089 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 20 Mar 2014 14:25:06 +0000 Subject: Implement read replacement to handle OEM codepages --- win32/winansi.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'win32') diff --git a/win32/winansi.c b/win32/winansi.c index 491285275..8ebe7b1af 100644 --- a/win32/winansi.c +++ b/win32/winansi.c @@ -16,6 +16,7 @@ #undef fwrite #undef puts #undef write +#undef read /* ANSI codes used by git: m, K @@ -25,6 +26,7 @@ */ static HANDLE console; +static HANDLE console_in; static WORD plain_attr; static WORD attr; static int negative; @@ -37,6 +39,10 @@ static void init(void) if (initialized) return; + console_in = GetStdHandle(STD_INPUT_HANDLE); + if (console_in == INVALID_HANDLE_VALUE) + console_in = NULL; + console = GetStdHandle(STD_OUTPUT_HANDLE); if (console == INVALID_HANDLE_VALUE) console = NULL; @@ -611,3 +617,23 @@ int winansi_write(int fd, const void *buf, size_t count) return ansi_emulate_write(fd, buf, count); } + +int winansi_read(int fd, void *buf, size_t count) +{ + int rv; + + rv = read(fd, buf, count); + if (!isatty(fd)) + return rv; + + init(); + + if (!console_in) + return rv; + + if ( rv > 0 ) { + OemToCharBuff(buf, buf, rv); + } + + return rv; +} -- cgit v1.2.3-55-g6feb