Skip to content

Commit 8644094

Browse files
authored
Merge pull request #2574 from rimrul/ucrt-strftime
mingw: use modern strftime implementation if possible
2 parents 9c98e1c + 6b80b39 commit 8644094

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

compat/mingw.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,15 @@ int mingw_utime (const char *file_name, const struct utimbuf *times)
11761176
size_t mingw_strftime(char *s, size_t max,
11771177
const char *format, const struct tm *tm)
11781178
{
1179-
size_t ret = strftime(s, max, format, tm);
1179+
/* a pointer to the original strftime in case we can't find the UCRT version */
1180+
static size_t (*fallback)(char *, size_t, const char *, const struct tm *) = strftime;
1181+
size_t ret;
1182+
DECLARE_PROC_ADDR(ucrtbase.dll, size_t, strftime, char *, size_t,
1183+
const char *, const struct tm *);
1184+
if (INIT_PROC_ADDR(strftime))
1185+
ret = strftime(s, max, format, tm);
1186+
else
1187+
ret = fallback(s, max, format, tm);
11801188

11811189
if (!ret && errno == EINVAL)
11821190
die("invalid strftime format: '%s'", format);

0 commit comments

Comments
 (0)