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