From e7dd5e45f6722ebb8bc8d5f612e0119bb02bc196 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Tue, 3 Dec 2024 09:18:24 -0800 Subject: [PATCH] Add wcsftime from musl. NFC See #23045 --- test/other/test_wcsftime.c | 37 ++++++++++++++++++++++++++++++++++++ test/other/test_wcsftime.out | 1 + test/test_other.py | 4 ++++ tools/system_libs.py | 2 ++ 4 files changed, 44 insertions(+) create mode 100644 test/other/test_wcsftime.c create mode 100644 test/other/test_wcsftime.out diff --git a/test/other/test_wcsftime.c b/test/other/test_wcsftime.c new file mode 100644 index 0000000000000..de403d8788a5b --- /dev/null +++ b/test/other/test_wcsftime.c @@ -0,0 +1,37 @@ +// Copyright 2017 The Emscripten Authors. All rights reserved. +// Emscripten is available under two separate licenses, the MIT license and the +// University of Illinois/NCSA Open Source License. Both these licenses can be +// found in the LICENSE file. + +#include +#include +#include +#include +#include +#include + +int main() { + struct tm tm; + wchar_t s[1000]; + + // Ensure all fields of `tm` are initialized correctly + // before we start messing with them. + time_t t = 0; + gmtime_r(&t, &tm); + + tm.tm_sec = 4; + tm.tm_min = 23; + tm.tm_hour = 20; + tm.tm_mday = 21; + tm.tm_mon = 1; + tm.tm_year = 74; + tm.tm_wday = 4; + tm.tm_yday = 51; + tm.tm_isdst = 0; + + const wchar_t *fmt = L"%m/%d/%Y %H:%M:%S %Z"; + wcsftime(s, sizeof(s), fmt, &tm); + printf("%ls -> %ls\n", fmt, s); + + return 0; +} diff --git a/test/other/test_wcsftime.out b/test/other/test_wcsftime.out new file mode 100644 index 0000000000000..507e1bc44ff2b --- /dev/null +++ b/test/other/test_wcsftime.out @@ -0,0 +1 @@ +%m/%d/%Y %H:%M:%S %Z -> 02/21/1974 20:23:04 GMT diff --git a/test/test_other.py b/test/test_other.py index 543fbffae1a52..630edf777ed55 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -6193,6 +6193,10 @@ def test_strptime_reentrant(self): def test_strftime(self): self.do_other_test('test_strftime.c') + @crossplatform + def test_wcsftime(self): + self.do_other_test('test_wcsftime.c') + @crossplatform def test_strftime_zZ(self): if MACOS: diff --git a/tools/system_libs.py b/tools/system_libs.py index b37363d588451..6f25349163344 100644 --- a/tools/system_libs.py +++ b/tools/system_libs.py @@ -1233,7 +1233,9 @@ def get_files(self): '__tm_to_secs.c', '__year_to_secs.c', '__month_to_secs.c', + 'wcsftime.c', ]) + libc_files += files_in_path( path='system/lib/libc/musl/src/legacy', filenames=['getpagesize.c', 'err.c', 'euidaccess.c'])