]> git.ipfire.org Git - thirdparty/git.git/commitdiff
mingw: use strftime() directly in UCRT builds
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Fri, 3 Apr 2026 09:56:23 +0000 (09:56 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 3 Apr 2026 17:36:48 +0000 (10:36 -0700)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
compat/mingw.c

index c667a2dcda7ac78aecc542345afce71d7f744ab7..338ec3535edf41c6ba7e5fa3f06be1a20e6e824a 100644 (file)
@@ -1394,6 +1394,9 @@ revert_attrs:
 size_t mingw_strftime(char *s, size_t max,
                      const char *format, const struct tm *tm)
 {
+#ifdef _UCRT
+       size_t ret = strftime(s, max, format, tm);
+#else
        /* a pointer to the original strftime in case we can't find the UCRT version */
        static size_t (*fallback)(char *, size_t, const char *, const struct tm *) = strftime;
        size_t ret;
@@ -1404,6 +1407,7 @@ size_t mingw_strftime(char *s, size_t max,
                ret = strftime(s, max, format, tm);
        else
                ret = fallback(s, max, format, tm);
+#endif
 
        if (!ret && errno == EINVAL)
                die("invalid strftime format: '%s'", format);