Skip to content

Commit 9b9e2dc

Browse files
authored
mingw: use strftime() directly in UCRT builds (#6130)
Currently, Git for Windows is built off of the MINGW64 tool chain. But this will have to change because [the MSYS2 project deprecated this tool chain in favor of UCRT64](https://www.msys2.org/news/#2026-03-15-deprecating-the-mingw64-environment). Of course, that's only possible because they dropped support for Windows 8.1, which Git for Windows will probably have to do relatively soon. The best time to do that is probably [the Git 3.0 inflection point](#6018) when we already promised to drop support for older Windows versions. To prepare for such a huge change, I investigated what needs to be changed in Git for Windows' source code. And the good news is there's actually not very much. This here patch seems to be the only change that's necessary, and not even _strictly_ necessary: the `mingw_strftime()` wrapper would still do the right thing. It would just uselessly load the same function that's already loaded, dynamically, again. - The `strerror()` override [is guarded by an `#ifndef _UCRT`](https://github.com/git-for-windows/git/blob/v2.53.0.windows.2/compat/mingw-posix.h#L294-L296), - `PRIuMAX` resolves to standard `"llu"` [via `<inttypes.h>`](https://github.com/git-for-windows/git/blob/v2.53.0.windows.2/compat/mingw-posix.h#L449-L454) (note that `__MINGW64_VERSION_MAJOR` is defined both in MINGW64 and UCRT64, by virtue of using the `mingw-w64-headers`), - [`__USE_MINGW_ANSI_STDIO=0`](https://github.com/git-for-windows/git/blob/v2.53.0.windows.2/config.mak.uname#L751C19-L751C33) is irrelevant because [`_UCRT` short-circuits it](https://github.com/git-for-windows/git-sdk-64/blob/08933e673c79b5db48419917a2b02746b390afc4/mingw64/include/inttypes.h#L33), and - `SNPRINTF_RETURNS_BOGUS` hasn't been set for Git for Windows' builds since ec47a33, i.e. for a _really_ long time.
2 parents b46b2ea + 1253fdb commit 9b9e2dc

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

compat/mingw.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,9 @@ int mingw_utime (const char *file_name, const struct utimbuf *times)
15091509
size_t mingw_strftime(char *s, size_t max,
15101510
const char *format, const struct tm *tm)
15111511
{
1512+
#ifdef _UCRT
1513+
size_t ret = strftime(s, max, format, tm);
1514+
#else
15121515
/* a pointer to the original strftime in case we can't find the UCRT version */
15131516
static size_t (*fallback)(char *, size_t, const char *, const struct tm *) = strftime;
15141517
size_t ret;
@@ -1519,6 +1522,7 @@ size_t mingw_strftime(char *s, size_t max,
15191522
ret = strftime(s, max, format, tm);
15201523
else
15211524
ret = fallback(s, max, format, tm);
1525+
#endif
15221526

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

0 commit comments

Comments
 (0)