Skip to content

Commit 9058ef2

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 9058ef2

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

compat/mingw-posix.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,11 @@ extern int (*lstat)(const char *file_name, struct stat *buf);
411411

412412
int mingw_utime(const char *file_name, const struct utimbuf *times);
413413
#define utime mingw_utime
414+
#ifndef _UCRT
414415
size_t mingw_strftime(char *s, size_t max,
415416
const char *format, const struct tm *tm);
416417
#define strftime mingw_strftime
418+
#endif
417419

418420
pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env,
419421
const char *dir,

compat/mingw.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,7 @@ int mingw_utime (const char *file_name, const struct utimbuf *times)
15051505
return rc;
15061506
}
15071507

1508+
#ifndef _UCRT
15081509
#undef strftime
15091510
size_t mingw_strftime(char *s, size_t max,
15101511
const char *format, const struct tm *tm)
@@ -1524,6 +1525,7 @@ size_t mingw_strftime(char *s, size_t max,
15241525
die("invalid strftime format: '%s'", format);
15251526
return ret;
15261527
}
1528+
#endif
15271529

15281530
unsigned int sleep (unsigned int seconds)
15291531
{

0 commit comments

Comments
 (0)