Skip to content

Commit 1020c97

Browse files
committed
mingw: use strftime() directly in UCRT builds
The `mingw_strftime()` wrapper exists to work around msvcrt.dll's incomplete `strftime()` implementation by dynamically loading the version from ucrtbase.dll at runtime via `LoadLibrary()` + `GetProcAddress()`. When the binary is already linked against UCRT (i.e. when building in the UCRT64 environment), the linked-in `strftime()` is the ucrtbase.dll version, making the dynamic loading needless churn: It's calling the very same code. Simply guard both the declaration and implementation so that the unnecessary work-around is skipped in UCRT builds. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent a5512bd commit 1020c97

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

compat/mingw.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,9 @@ int mingw_utime (const char *file_name, const struct utimbuf *times)
15091509
size_t mingw_strftime(char *s, size_t max,
15101510
const char *format, const struct tm *tm)
15111511
{
1512+
#ifdef _UCRT
1513+
size_t ret = strftime(s, max, format, tm)
1514+
#else
15121515
/* a pointer to the original strftime in case we can't find the UCRT version */
15131516
static size_t (*fallback)(char *, size_t, const char *, const struct tm *) = strftime;
15141517
size_t ret;
@@ -1519,6 +1522,7 @@ size_t mingw_strftime(char *s, size_t max,
15191522
ret = strftime(s, max, format, tm);
15201523
else
15211524
ret = fallback(s, max, format, tm);
1525+
#endif
15221526

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

0 commit comments

Comments
 (0)