Skip to content

Commit 9a9f2a0

Browse files
committed
Add wcsftime from musl. NFC
See #23045
1 parent 85725fa commit 9a9f2a0

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

test/other/test_wcsftime.c

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2017 The Emscripten Authors. All rights reserved.
2+
// Emscripten is available under two separate licenses, the MIT license and the
3+
// University of Illinois/NCSA Open Source License. Both these licenses can be
4+
// found in the LICENSE file.
5+
6+
#include <assert.h>
7+
#include <time.h>
8+
#include <stdio.h>
9+
#include <string.h>
10+
#include <stdlib.h>
11+
#include <wchar.h>
12+
13+
int main() {
14+
struct tm tm;
15+
wchar_t s[1000];
16+
size_t size;
17+
18+
// Ensure all fields of `tm` are initialized correctly
19+
// before we start messing with them.
20+
time_t t = 0;
21+
gmtime_r(&t, &tm);
22+
23+
tm.tm_sec = 4;
24+
tm.tm_min = 23;
25+
tm.tm_hour = 20;
26+
tm.tm_mday = 21;
27+
tm.tm_mon = 1;
28+
tm.tm_year = 74;
29+
tm.tm_wday = 4;
30+
tm.tm_yday = 51;
31+
tm.tm_isdst = 0;
32+
33+
// Test %% escaping
34+
const wchar_t *fmt = L"%m/%d/%Y %H:%M:%S %Z";
35+
wcsftime(s, sizeof(s), fmt, &tm);
36+
printf("%ls -> %ls\n", fmt, s);
37+
38+
return 0;
39+
}

test/other/test_wcsftime.out

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
%m/%d/%Y %H:%M:%S %Z -> 02/21/1974 20:23:04 GMT

test/test_other.py

+4
Original file line numberDiff line numberDiff line change
@@ -6193,6 +6193,10 @@ def test_strptime_reentrant(self):
61936193
def test_strftime(self):
61946194
self.do_other_test('test_strftime.c')
61956195

6196+
@crossplatform
6197+
def test_wcsftime(self):
6198+
self.do_other_test('test_wcsftime.c')
6199+
61966200
@crossplatform
61976201
def test_strftime_zZ(self):
61986202
if MACOS:

tools/system_libs.py

+2
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,9 @@ def get_files(self):
12331233
'__tm_to_secs.c',
12341234
'__year_to_secs.c',
12351235
'__month_to_secs.c',
1236+
'wcsftime.c',
12361237
])
1238+
12371239
libc_files += files_in_path(
12381240
path='system/lib/libc/musl/src/legacy',
12391241
filenames=['getpagesize.c', 'err.c', 'euidaccess.c'])

0 commit comments

Comments
 (0)