Skip to content

Commit

Permalink
Fix read
Browse files Browse the repository at this point in the history
  • Loading branch information
lupyuen committed Jan 26, 2024
1 parent dd01611 commit 7fe054b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,8 @@ Then we...

- [Add read](https://github.com/lupyuen/tcc-riscv32-wasm/commit/7309abf30c12ade7db89a59539d4e3e04956562a)

- [Add sprintf, snprintf](https://github.com/lupyuen/tcc-riscv32-wasm/commit/dd0161168815d570259e08d4bf0370a363e6e6e7)

When we run it: open() tries to open `hello.c` and read the file yay!

```text
Expand Down
Binary file modified docs/tcc-wasm.wasm
Binary file not shown.
Binary file modified tcc-wasm.wasm
Binary file not shown.
7 changes: 7 additions & 0 deletions zig/tcc-wasm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ export fn open(path: [*:0]const u8, oflag: c_uint, ...) c_int {

export fn read(fd0: c_int, buf: [*:0]u8, nbyte: size_t) isize {
debug("read: fd={}, nbyte={}", .{ fd0, nbyte });
// Return the contents once only
if (!first_read) {
debug("read: return 0", .{});
return 0;
}
first_read = false;
const s =
\\int main(int argc, char *argv[]) {
\\ printf("Hello, World!!\n");
Expand All @@ -67,6 +73,7 @@ export fn read(fd0: c_int, buf: [*:0]u8, nbyte: size_t) isize {
}

var fd: c_int = 3;
var first_read: bool = true;

///////////////////////////////////////////////////////////////////////////////
// Semaphore Functions
Expand Down

0 comments on commit 7fe054b

Please sign in to comment.