diff options
author | Ron Yorston <rmy@pobox.com> | 2014-03-20 15:10:56 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2014-03-20 15:10:56 +0000 |
commit | 88deb9583290c2a4880903249eb9c5ed6ac05466 (patch) | |
tree | fea35ee1ab1a9eb9621ba0c990e6468ac32b8e7c | |
parent | 19633819727ac696e51e0e1f5a6e65fd29f5c089 (diff) | |
download | busybox-w32-88deb9583290c2a4880903249eb9c5ed6ac05466.tar.gz busybox-w32-88deb9583290c2a4880903249eb9c5ed6ac05466.tar.bz2 busybox-w32-88deb9583290c2a4880903249eb9c5ed6ac05466.zip |
Implement getc replacement
-rw-r--r-- | include/mingw.h | 2 | ||||
-rw-r--r-- | win32/winansi.c | 24 |
2 files changed, 26 insertions, 0 deletions
diff --git a/include/mingw.h b/include/mingw.h index 970eb5ea4..c737441a6 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
@@ -148,6 +148,7 @@ int winansi_printf(const char *format, ...) __attribute__((format (printf, 1, 2) | |||
148 | int winansi_fprintf(FILE *stream, const char *format, ...) __attribute__((format (printf, 2, 3))); | 148 | int winansi_fprintf(FILE *stream, const char *format, ...) __attribute__((format (printf, 2, 3))); |
149 | int winansi_write(int fd, const void *buf, size_t count); | 149 | int winansi_write(int fd, const void *buf, size_t count); |
150 | int winansi_read(int fd, void *buf, size_t count); | 150 | int winansi_read(int fd, void *buf, size_t count); |
151 | int winansi_getc(FILE *stream); | ||
151 | #define putchar winansi_putchar | 152 | #define putchar winansi_putchar |
152 | #define puts winansi_puts | 153 | #define puts winansi_puts |
153 | #define fwrite winansi_fwrite | 154 | #define fwrite winansi_fwrite |
@@ -156,6 +157,7 @@ int winansi_read(int fd, void *buf, size_t count); | |||
156 | #define fprintf(...) winansi_fprintf(__VA_ARGS__) | 157 | #define fprintf(...) winansi_fprintf(__VA_ARGS__) |
157 | #define write winansi_write | 158 | #define write winansi_write |
158 | #define read winansi_read | 159 | #define read winansi_read |
160 | #define getc winansi_getc | ||
159 | 161 | ||
160 | int winansi_get_terminal_width_height(struct winsize *win); | 162 | int winansi_get_terminal_width_height(struct winsize *win); |
161 | 163 | ||
diff --git a/win32/winansi.c b/win32/winansi.c index 8ebe7b1af..e2b18b274 100644 --- a/win32/winansi.c +++ b/win32/winansi.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #undef puts | 17 | #undef puts |
18 | #undef write | 18 | #undef write |
19 | #undef read | 19 | #undef read |
20 | #undef getc | ||
20 | 21 | ||
21 | /* | 22 | /* |
22 | ANSI codes used by git: m, K | 23 | ANSI codes used by git: m, K |
@@ -637,3 +638,26 @@ int winansi_read(int fd, void *buf, size_t count) | |||
637 | 638 | ||
638 | return rv; | 639 | return rv; |
639 | } | 640 | } |
641 | |||
642 | int winansi_getc(FILE *stream) | ||
643 | { | ||
644 | int rv; | ||
645 | |||
646 | rv = getc(stream); | ||
647 | if (!isatty(fileno(stream))) | ||
648 | return rv; | ||
649 | |||
650 | init(); | ||
651 | |||
652 | if (!console_in) | ||
653 | return rv; | ||
654 | |||
655 | if ( rv != EOF ) { | ||
656 | unsigned char c = (unsigned char)rv; | ||
657 | char *s = (char *)&c; | ||
658 | OemToCharBuff(s, s, 1); | ||
659 | rv = (int)c; | ||
660 | } | ||
661 | |||
662 | return rv; | ||
663 | } | ||