Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle trailing % in strftime #23045

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions system/lib/libc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Some changes have been made to the version that was taken from upstream, includi
* Switch to using the wasi `fd_write` syscall instead of `writev`.
* Simplify stdout stream handling: do not support seeking, terminal handling, etc., as it just increases code size and Emscripten doesn't have those features anyhow.
* Setting `_POSIX_REALTIME_SIGNALS` and `_POSIX_SPAWN` macros to -1, to exclude unsupported functions.
* Handling trailing % in `strftime` and `wcsftime` format strings.

Copy log.c and log2.c from earlier version of musl which result in smaller
binary size since they do not rely data tables in log_data.c and log2_data.c.
Expand Down
6 changes: 6 additions & 0 deletions system/lib/libc/musl/src/time/strftime.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,13 @@ size_t __strftime_l(char *restrict s, size_t n, const char *restrict f, const st
s[l] = 0;
return l;
}
#ifdef __EMSCRIPTEN__
// Handle trailing % by outputting a % rather than returning 0. Ideally
// this 6 character change could be upstreamed into musl...
if (*f != '%' || !f[1]) {
hoodmane marked this conversation as resolved.
Show resolved Hide resolved
#else
if (*f != '%') {
#endif
s[l++] = *f;
continue;
}
Expand Down
3 changes: 3 additions & 0 deletions test/other/test_strftime.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,5 +307,8 @@ int main() {
size = strftime(s, sizeof(s), "%Ec", &tm);
TEST(!cmp(s, "Mon Dec 17 00:00:00 2018"), "strftime test #36a", s);

size = strftime(s, sizeof(s), "trailing %", &tm);
TEST((size == 10), "strftime test #37", s);
TEST(!cmp(s, "trailing %"), "strftime test #37", s);
return 0;
}
Loading