Skip to content

Commit

Permalink
Change L.%u to L.0, .rela%s to .rela.text
Browse files Browse the repository at this point in the history
  • Loading branch information
lupyuen committed Jan 27, 2024
1 parent 2f06401 commit 3c8e433
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Binary file modified docs/tcc-wasm.wasm
Binary file not shown.
Binary file modified tcc-wasm.wasm
Binary file not shown.
20 changes: 16 additions & 4 deletions zig/tcc-wasm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,29 @@ export fn fprintf(stream: *FILE, format: [*:0]const u8, ...) c_int {

export fn sprintf(str: [*:0]u8, format: [*:0]const u8, ...) c_int {
debug("TODO: sprintf: format={s}", .{format});
_ = memcpy(str, format, strlen(format));
str[strlen(format)] = 0;
if (strcmp(format, "L.%u") == 0) {
const s = "L.0";
_ = memcpy(str, s, strlen(s));
str[strlen(s)] = 0;
} else {
_ = memcpy(str, format, strlen(format));
str[strlen(format)] = 0;
}
debug("TODO: sprintf: return str={s}", .{str});
return @intCast(strlen(str));
}

export fn snprintf(str: [*:0]u8, size: size_t, format: [*:0]const u8, ...) c_int {
debug("TODO: snprintf: size={}, format={s}", .{ size, format });
// TODO: Catch overflow
_ = memcpy(str, format, strlen(format));
str[strlen(format)] = 0;
if (strcmp(format, ".rela%s") == 0) {
const s = ".rela.text";
_ = memcpy(str, s, strlen(s));
str[strlen(s)] = 0;
} else {
_ = memcpy(str, format, strlen(format));
str[strlen(format)] = 0;
}
debug("TODO: snprintf: return str={s}", .{str});
return @intCast(strlen(str));
}
Expand Down

0 comments on commit 3c8e433

Please sign in to comment.