Skip to content

Commit 36d591e

Browse files
committed
Add fprintf
1 parent c76b671 commit 36d591e

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ Then we...
440440

441441
- [Add sscanf](https://github.com/lupyuen/tcc-riscv32-wasm/commit/abf18acd6053b852363afa9adefcc81501f334ed)
442442

443-
- [Add vsnprintf](https://github.com/lupyuen/tcc-riscv32-wasm/commit/5bc7d6b4c002a3ee16161d819d1c3300b55a91d3)
443+
- [Add vsnprintf and fflush](https://github.com/lupyuen/tcc-riscv32-wasm/commit/c76b671e771d6ba4bb62230e1546aeb3e8637850)
444444

445445
When we run it: open() tries to open `hello.c` and create a Semaphore yay!
446446

docs/tcc-wasm.wasm

2.46 KB
Binary file not shown.

tcc-wasm.wasm

2.46 KB
Binary file not shown.

zig/tcc-wasm.zig

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export fn sem_wait(sem: *sem_t) c_int {
6969
const sem_t = opaque {};
7070

7171
///////////////////////////////////////////////////////////////////////////////
72-
// sscanf, vsnprintf
72+
// Varargs Functions
7373

7474
export fn sscanf(str: [*:0]const u8, format: [*:0]const u8, ...) c_int {
7575
debug("TODO: sscanf: str={s}, format={s}", .{ str, format });
@@ -92,7 +92,13 @@ export fn vsnprintf(str: [*:0]u8, size: size_t, format: [*:0]const u8, ...) c_in
9292
return @intCast(strlen(format));
9393
}
9494

95+
export fn fprintf(stream: *FILE, format: [*:0]const u8, ...) c_int {
96+
debug("fprintf: stream={*}, format={s}", .{ stream, format });
97+
return @intCast(strlen(format));
98+
}
99+
95100
const size_t = c_ulong;
101+
const FILE = opaque {};
96102

97103
///////////////////////////////////////////////////////////////////////////////
98104
// Memory Allocator for malloc
@@ -320,9 +326,6 @@ pub export fn fdopen(_: c_int) c_int {
320326
pub export fn fopen(_: c_int) c_int {
321327
@panic("TODO: fopen");
322328
}
323-
pub export fn fprintf(_: c_int) c_int {
324-
@panic("TODO: fprintf");
325-
}
326329
pub export fn fputc(_: c_int) c_int {
327330
@panic("TODO: fputc");
328331
}

0 commit comments

Comments
 (0)