Closed
Description
Emscripten's strftime does not parse quoted percent correctly. It treats %%z
as %
+ %z
instead of %%
+ z
. For %%z
the function returns %+0000
instead of %z
. I detected the problem in CPython port to Emscripten.
Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.1 (1934a98e709b57d3592b8272d3f1264a72c089e4)
clang version 14.0.0 (https://github.com/llvm/llvm-project f142c45f1e494f8dbdcc1bcf14122d128ac8f3fe)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /emsdk/upstream/bin
reproducer
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int
main(void)
{
char buf[256];
char *fmt = "%H:%M:%S %%Z=%Z %%z=%z";
time_t t;
struct tm *tm;
t = time(NULL);
tm = localtime(&t);
strftime(buf, sizeof(buf), fmt, tm);
fprintf(stdout, "%s -> %s\n", fmt, buf);
return 0;
}
glibc output
# gcc -o fmttime fmttime.c && ./fmttime
%H:%M:%S %%Z=%Z %%z=%z -> 15:33:56 %Z=UTC %z=+0000
emcc + node output
# emcc -o fmttime.js fmttime.c && node fmttime.js
%H:%M:%S %%Z=%Z %%z=%z -> 15:34:28 %Coordinated Universal Time=Coordinated Universal Time %+0000=+0000
Metadata
Metadata
Assignees
Labels
No labels