From 9058ef21d17a61049d38fc69ca0c4f73aa6ba3d9 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 17 Mar 2026 08:08:16 +0100 Subject: [PATCH] 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 --- compat/mingw-posix.h | 2 ++ compat/mingw.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/compat/mingw-posix.h b/compat/mingw-posix.h index 9158f89d89d239..15c4f741338f37 100644 --- a/compat/mingw-posix.h +++ b/compat/mingw-posix.h @@ -411,9 +411,11 @@ extern int (*lstat)(const char *file_name, struct stat *buf); int mingw_utime(const char *file_name, const struct utimbuf *times); #define utime mingw_utime +#ifndef _UCRT size_t mingw_strftime(char *s, size_t max, const char *format, const struct tm *tm); #define strftime mingw_strftime +#endif pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env, const char *dir, diff --git a/compat/mingw.c b/compat/mingw.c index 5a9807e7a42b41..3b6732cea93a36 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1505,6 +1505,7 @@ int mingw_utime (const char *file_name, const struct utimbuf *times) return rc; } +#ifndef _UCRT #undef strftime size_t mingw_strftime(char *s, size_t max, const char *format, const struct tm *tm) @@ -1524,6 +1525,7 @@ size_t mingw_strftime(char *s, size_t max, die("invalid strftime format: '%s'", format); return ret; } +#endif unsigned int sleep (unsigned int seconds) {