Skip to content

Commit 536da63

Browse files
authored
Add wcsftime from musl. NFC (#23061)
See #23045
1 parent 89cbc4e commit 536da63

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

test/other/test_wcsftime.c

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
17+
// Ensure all fields of `tm` are initialized correctly
18+
// before we start messing with them.
19+
time_t t = 0;
20+
gmtime_r(&t, &tm);
21+
22+
tm.tm_sec = 4;
23+
tm.tm_min = 23;
24+
tm.tm_hour = 20;
25+
tm.tm_mday = 21;
26+
tm.tm_mon = 1;
27+
tm.tm_year = 74;
28+
tm.tm_wday = 4;
29+
tm.tm_yday = 51;
30+
tm.tm_isdst = 0;
31+
32+
const wchar_t *fmt = L"%m/%d/%Y %H:%M:%S %Z";
33+
wcsftime(s, sizeof(s), fmt, &tm);
34+
printf("%ls -> %ls\n", fmt, s);
35+
36+
return 0;
37+
}

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)