diff options
author | Ron Yorston <rmy@pobox.com> | 2014-03-20 14:25:06 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2014-03-20 14:31:23 +0000 |
commit | 19633819727ac696e51e0e1f5a6e65fd29f5c089 (patch) | |
tree | 6bf83cc85774d36194fe06e3854a04c8188eccc9 /win32 | |
parent | 85aca2f0f45f199458a6cfdcf3eee27c4be2a3a6 (diff) | |
download | busybox-w32-19633819727ac696e51e0e1f5a6e65fd29f5c089.tar.gz busybox-w32-19633819727ac696e51e0e1f5a6e65fd29f5c089.tar.bz2 busybox-w32-19633819727ac696e51e0e1f5a6e65fd29f5c089.zip |
Implement read replacement to handle OEM codepages
Diffstat (limited to 'win32')
-rw-r--r-- | win32/winansi.c | 26 |
1 files changed, 26 insertions, 0 deletions
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 @@ | |||
16 | #undef fwrite | 16 | #undef fwrite |
17 | #undef puts | 17 | #undef puts |
18 | #undef write | 18 | #undef write |
19 | #undef read | ||
19 | 20 | ||
20 | /* | 21 | /* |
21 | ANSI codes used by git: m, K | 22 | ANSI codes used by git: m, K |
@@ -25,6 +26,7 @@ | |||
25 | */ | 26 | */ |
26 | 27 | ||
27 | static HANDLE console; | 28 | static HANDLE console; |
29 | static HANDLE console_in; | ||
28 | static WORD plain_attr; | 30 | static WORD plain_attr; |
29 | static WORD attr; | 31 | static WORD attr; |
30 | static int negative; | 32 | static int negative; |
@@ -37,6 +39,10 @@ static void init(void) | |||
37 | if (initialized) | 39 | if (initialized) |
38 | return; | 40 | return; |
39 | 41 | ||
42 | console_in = GetStdHandle(STD_INPUT_HANDLE); | ||
43 | if (console_in == INVALID_HANDLE_VALUE) | ||
44 | console_in = NULL; | ||
45 | |||
40 | console = GetStdHandle(STD_OUTPUT_HANDLE); | 46 | console = GetStdHandle(STD_OUTPUT_HANDLE); |
41 | if (console == INVALID_HANDLE_VALUE) | 47 | if (console == INVALID_HANDLE_VALUE) |
42 | console = NULL; | 48 | console = NULL; |
@@ -611,3 +617,23 @@ int winansi_write(int fd, const void *buf, size_t count) | |||
611 | 617 | ||
612 | return ansi_emulate_write(fd, buf, count); | 618 | return ansi_emulate_write(fd, buf, count); |
613 | } | 619 | } |
620 | |||
621 | int winansi_read(int fd, void *buf, size_t count) | ||
622 | { | ||
623 | int rv; | ||
624 | |||
625 | rv = read(fd, buf, count); | ||
626 | if (!isatty(fd)) | ||
627 | return rv; | ||
628 | |||
629 | init(); | ||
630 | |||
631 | if (!console_in) | ||
632 | return rv; | ||
633 | |||
634 | if ( rv > 0 ) { | ||
635 | OemToCharBuff(buf, buf, rv); | ||
636 | } | ||
637 | |||
638 | return rv; | ||
639 | } | ||