| ... | ... | @@ -520,12 +520,15 @@ uint32_t wasi_snapshot_preview1_fd_read(uint32_t fd, uint32_t iovs, uint32_t iov |
| 520 | 520 | default: panic("unimplemented: fd_read special file"); |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | if (fds[fd].stream == NULL) { |
| 524 | store32_align2(res_size_ptr, 0); |
| 525 | return wasi_errno_success; |
| 526 | } |
| 527 | |
| 523 | 528 | size_t size = 0; |
| 524 | 529 | for (uint32_t i = 0; i < iovs_len; i += 1) { |
| 525 | 530 | uint32_t len = load32_align2(&iovs_ptr[i].len); |
| 526 | | size_t read_size = 0; |
| 527 | | if (fds[fd].stream != NULL) |
| 528 | | read_size = fread(&m[load32_align2(&iovs_ptr[i].ptr)], 1, len, fds[fd].stream); |
| 531 | size_t read_size = fread(&m[load32_align2(&iovs_ptr[i].ptr)], 1, len, fds[fd].stream); |
| 529 | 532 | size += read_size; |
| 530 | 533 | if (read_size < len) break; |
| 531 | 534 | } |
| ... | ... | @@ -633,8 +636,10 @@ uint32_t wasi_snapshot_preview1_fd_pwrite(uint32_t fd, uint32_t iovs, uint32_t i |
| 633 | 636 | } |
| 634 | 637 | |
| 635 | 638 | fpos_t pos; |
| 636 | | if (fgetpos(fds[fd].stream, &pos) < 0) return wasi_errno_io; |
| 637 | | if (fseek(fds[fd].stream, offset, SEEK_SET) < 0) return wasi_errno_io; |
| 639 | if (fds[fd].stream != NULL) { |
| 640 | if (fgetpos(fds[fd].stream, &pos) < 0) return wasi_errno_io; |
| 641 | if (fseek(fds[fd].stream, offset, SEEK_SET) < 0) return wasi_errno_io; |
| 642 | } |
| 638 | 643 | |
| 639 | 644 | size_t size = 0; |
| 640 | 645 | for (uint32_t i = 0; i < iovs_len; i += 1) { |
| ... | ... | @@ -648,7 +653,9 @@ uint32_t wasi_snapshot_preview1_fd_pwrite(uint32_t fd, uint32_t iovs, uint32_t i |
| 648 | 653 | if (written_size < len) break; |
| 649 | 654 | } |
| 650 | 655 | |
| 651 | | if (fsetpos(fds[fd].stream, &pos) < 0) return wasi_errno_io; |
| 656 | if (fds[fd].stream != NULL) { |
| 657 | if (fsetpos(fds[fd].stream, &pos) < 0) return wasi_errno_io; |
| 658 | } |
| 652 | 659 | |
| 653 | 660 | if (size > 0) { |
| 654 | 661 | time_t now = time(NULL); |
| ... | ... | @@ -964,6 +971,11 @@ uint32_t wasi_snapshot_preview1_fd_pread(uint32_t fd, uint32_t iovs, uint32_t io |
| 964 | 971 | default: panic("unimplemented: fd_pread special file"); |
| 965 | 972 | } |
| 966 | 973 | |
| 974 | if (fds[fd].stream == NULL) { |
| 975 | store32_align2(res_size_ptr, 0); |
| 976 | return wasi_errno_success; |
| 977 | } |
| 978 | |
| 967 | 979 | fpos_t pos; |
| 968 | 980 | if (fgetpos(fds[fd].stream, &pos) < 0) return wasi_errno_io; |
| 969 | 981 | if (fseek(fds[fd].stream, offset, SEEK_SET) < 0) return wasi_errno_io; |