Skip to content

Commit e7f9aa4

Browse files
rimrulGit for Windows Build Agent
authored and
Git for Windows Build Agent
committed
mingw: use modern strftime implementation if possible
Microsoft introduced a new "Universal C Runtime Library" (UCRT) with Visual Studio 2015. The UCRT comes with a new strftime() implementation that supports more date formats. We link git against the older "Microsoft Visual C Runtime Library" (MSVCRT), so to use the UCRT strftime() we need to load it from ucrtbase.dll using DECLARE_PROC_ADDR()/INIT_PROC_ADDR(). Most supported Windows systems should have recieved the UCRT via Windows update, but in some cases only MSVCRT might be available. In that case we fall back to using that implementation. This fixes #2495 Signed-off-by: Matthias Aßhauer <[email protected]>
1 parent 0028934 commit e7f9aa4

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

compat/mingw.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,15 @@ int mingw_utime (const char *file_name, const struct utimbuf *times)
964964
size_t mingw_strftime(char *s, size_t max,
965965
const char *format, const struct tm *tm)
966966
{
967-
size_t ret = strftime(s, max, format, tm);
967+
/* a pointer to the original strftime in case we can't find the UCRT version */
968+
static size_t (*fallback)(char *, size_t, const char *, const struct tm *) = strftime;
969+
size_t ret;
970+
DECLARE_PROC_ADDR(ucrtbase.dll, size_t, strftime, char *, size_t,
971+
const char *, const struct tm *);
972+
if (INIT_PROC_ADDR(strftime))
973+
ret = strftime(s, max, format, tm);
974+
else
975+
ret = fallback(s, max, format, tm);
968976

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

0 commit comments

Comments
 (0)