|
7 | 7 | #include "platform_api_extension.h" |
8 | 8 | #include "libc_errno.h" |
9 | 9 |
|
| 10 | +#include <stdio.h> |
10 | 11 | #include <string.h> |
11 | 12 | #include <stdlib.h> |
12 | 13 | #include <unistd.h> |
@@ -720,17 +721,34 @@ os_writev(os_file_handle handle, const struct __wasi_ciovec_t *iov, int iovcnt, |
720 | 721 | if (handle->raw_fd >= 0) { |
721 | 722 | /* Use the real OS file descriptor */ |
722 | 723 | for (int i = 0; i < iovcnt; i++) { |
723 | | - ssize_t bytes_written = |
724 | | - write(handle->raw_fd, iov[i].buf, iov[i].buf_len); |
| 724 | + ssize_t bytes_written = 0; |
| 725 | + if (handle->raw_fd == STDOUT_FILENO |
| 726 | + || handle->raw_fd == STDERR_FILENO) { |
| 727 | + /* Zephyr still does not support write to stdout with |
| 728 | + * picolibc. fprintf works. so we use it here. */ |
| 729 | + fprintf(stdout, "%*s", (int)iov[i].buf_len, |
| 730 | + (char *)iov[i].buf); |
| 731 | + |
| 732 | + /* fprintf will also sometimes return more bytes than we |
| 733 | + * request, so we just bypass here */ |
| 734 | + bytes_written = iov[i].buf_len; |
| 735 | + } |
| 736 | + else { |
| 737 | + bytes_written = |
| 738 | + write(handle->raw_fd, iov[i].buf, iov[i].buf_len); |
| 739 | + } |
| 740 | + |
725 | 741 | if (bytes_written < 0) |
726 | 742 | return convert_errno(errno); |
| 743 | + |
727 | 744 | total_written += bytes_written; |
728 | 745 | } |
729 | 746 | } |
730 | 747 | else { |
731 | 748 | /* No real fd: fall back to fwrite on stdout/stderr */ |
732 | 749 | FILE *f = (handle->fd == STDERR_FILENO) ? stderr : stdout; |
733 | 750 | for (int i = 0; i < iovcnt; i++) { |
| 751 | + printf("2222\n"); |
734 | 752 | ssize_t bytes_written = |
735 | 753 | fwrite(iov[i].buf, 1, iov[i].buf_len, f); |
736 | 754 | if (bytes_written < 0) |
|
0 commit comments