Skip to content

Commit dac1f99

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 31dccb7 commit dac1f99

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
@@ -1176,7 +1176,15 @@ int mingw_utime (const char *file_name, const struct utimbuf *times)
11761176
size_t mingw_strftime(char *s, size_t max,
11771177
const char *format, const struct tm *tm)
11781178
{
1179-
size_t ret = strftime(s, max, format, tm);
1179+
/* a pointer to the original strftime in case we can't find the UCRT version */
1180+
static size_t (*fallback)(char *, size_t, const char *, const struct tm *) = strftime;
1181+
size_t ret;
1182+
DECLARE_PROC_ADDR(ucrtbase.dll, size_t, strftime, char *, size_t,
1183+
const char *, const struct tm *);
1184+
if (INIT_PROC_ADDR(strftime))
1185+
ret = strftime(s, max, format, tm);
1186+
else
1187+
ret = fallback(s, max, format, tm);
11801188

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

0 commit comments

Comments
 (0)