|
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> |
@@ -742,17 +743,34 @@ os_writev(os_file_handle handle, const struct __wasi_ciovec_t *iov, int iovcnt, |
742 | 743 | if (handle->raw_fd >= 0) { |
743 | 744 | /* Use the real OS file descriptor */ |
744 | 745 | for (int i = 0; i < iovcnt; i++) { |
745 | | - ssize_t bytes_written = |
746 | | - write(handle->raw_fd, iov[i].buf, iov[i].buf_len); |
| 746 | + ssize_t bytes_written = 0; |
| 747 | + if (handle->raw_fd == STDOUT_FILENO |
| 748 | + || handle->raw_fd == STDERR_FILENO) { |
| 749 | + /* Zephyr still does not support write to stdout with |
| 750 | + * picolibc. fprintf works. so we use it here. */ |
| 751 | + fprintf(stdout, "%*s", (int)iov[i].buf_len, |
| 752 | + (char *)iov[i].buf); |
| 753 | + |
| 754 | + /* fprintf will also sometimes return more bytes than we |
| 755 | + * request, so we just bypass here */ |
| 756 | + bytes_written = iov[i].buf_len; |
| 757 | + } |
| 758 | + else { |
| 759 | + bytes_written = |
| 760 | + write(handle->raw_fd, iov[i].buf, iov[i].buf_len); |
| 761 | + } |
| 762 | + |
747 | 763 | if (bytes_written < 0) |
748 | 764 | return convert_errno(errno); |
| 765 | + |
749 | 766 | total_written += bytes_written; |
750 | 767 | } |
751 | 768 | } |
752 | 769 | else { |
753 | 770 | /* No real fd: fall back to fwrite on stdout/stderr */ |
754 | 771 | FILE *f = (handle->fd == STDERR_FILENO) ? stderr : stdout; |
755 | 772 | for (int i = 0; i < iovcnt; i++) { |
| 773 | + printf("2222\n"); |
756 | 774 | ssize_t bytes_written = |
757 | 775 | fwrite(iov[i].buf, 1, iov[i].buf_len, f); |
758 | 776 | if (bytes_written < 0) |
|
0 commit comments