diff options
-rw-r--r-- | win32/winansi.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/win32/winansi.c b/win32/winansi.c index 256ef4fa9..e36f7565b 100644 --- a/win32/winansi.c +++ b/win32/winansi.c | |||
@@ -475,17 +475,24 @@ int winansi_puts(const char *s) | |||
475 | return (winansi_fputs(s, stdout) == EOF || putchar('\n') == EOF) ? EOF : 0; | 475 | return (winansi_fputs(s, stdout) == EOF || putchar('\n') == EOF) ? EOF : 0; |
476 | } | 476 | } |
477 | 477 | ||
478 | static void check_pipe(FILE *stream) | 478 | static void check_pipe_fd(int fd) |
479 | { | 479 | { |
480 | if (GetLastError() == ERROR_NO_DATA && ferror(stream)) { | 480 | if (GetLastError() == ERROR_NO_DATA) { |
481 | int fd = fileno(stream); | 481 | if (GetFileType((HANDLE)_get_osfhandle(fd)) == FILE_TYPE_PIPE) { |
482 | if (fd != -1 && | ||
483 | GetFileType((HANDLE)_get_osfhandle(fd)) == FILE_TYPE_PIPE) { | ||
484 | errno = EPIPE; | 482 | errno = EPIPE; |
485 | } | 483 | } |
486 | } | 484 | } |
487 | } | 485 | } |
488 | 486 | ||
487 | static void check_pipe(FILE *stream) | ||
488 | { | ||
489 | int fd = fileno(stream); | ||
490 | |||
491 | if (fd != -1 && ferror(stream)) { | ||
492 | check_pipe_fd(fd); | ||
493 | } | ||
494 | } | ||
495 | |||
489 | size_t winansi_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) | 496 | size_t winansi_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) |
490 | { | 497 | { |
491 | size_t lsize, lmemb, ret; | 498 | size_t lsize, lmemb, ret; |
@@ -675,8 +682,15 @@ static int ansi_emulate_write(int fd, const void *buf, size_t count) | |||
675 | 682 | ||
676 | int winansi_write(int fd, const void *buf, size_t count) | 683 | int winansi_write(int fd, const void *buf, size_t count) |
677 | { | 684 | { |
678 | if (!is_console(fd)) | 685 | if (!is_console(fd)) { |
679 | return write(fd, buf, count); | 686 | int ret; |
687 | |||
688 | SetLastError(0); | ||
689 | if ((ret=write(fd, buf, count)) == -1) { | ||
690 | check_pipe_fd(fd); | ||
691 | } | ||
692 | return ret; | ||
693 | } | ||
680 | 694 | ||
681 | return ansi_emulate_write(fd, buf, count); | 695 | return ansi_emulate_write(fd, buf, count); |
682 | } | 696 | } |