* [PATCH] win32: ensure that `localtime_r()` is declared even in i686 builds
@ 2026-06-22 8:44 Johannes Schindelin via GitGitGadget
2026-06-22 9:11 ` Patrick Steinhardt
0 siblings, 1 reply; 2+ messages in thread
From: Johannes Schindelin via GitGitGadget @ 2026-06-22 8:44 UTC (permalink / raw)
To: git; +Cc: Johannes Schindelin, Johannes Schindelin
From: Johannes Schindelin <johannes.schindelin@gmx.de>
The `__MINGW64__` constant is defined, surprise, surprise, only when
building for a 64-bit CPU architecture.
Therefore using it as a guard to define `_POSIX_C_SOURCE` (so that
`localtime_r()` is declared, among other functions) is not enough, we
also need to check `__MINGW32__`.
Technically, the latter constant is defined even for 64-bit builds. But
let's make things a bit easier to understand by testing for both
constants.
Making it so fixes this compile warning (turned error in GCC v14.1):
archive-zip.c: In function 'dos_time':
archive-zip.c:612:9: error: implicit declaration of function 'localtime_r';
did you mean 'localtime_s'? [-Wimplicit-function-declaration]
612 | localtime_r(&time, &tm);
| ^~~~~~~~~~~
| localtime_s
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
win32: ensure that localtime_r() is declared even in i686 builds
Git for Windows plans on reducing the scope of its i686 support after
v2.55.0 even further, therefore this patch (which I had forgotten about)
needs to be in that version.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2157%2Fdscho%2FFix-i686-build-with-GCC-v14-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2157/dscho/Fix-i686-build-with-GCC-v14-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2157
compat/posix.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/compat/posix.h b/compat/posix.h
index 2f01564b0d..e2e794cad7 100644
--- a/compat/posix.h
+++ b/compat/posix.h
@@ -56,7 +56,7 @@
# define UNUSED
#endif
-#ifdef __MINGW64__
+#if defined(__MINGW32__) || defined(__MINGW64__)
#define _POSIX_C_SOURCE 1
#elif defined(__sun__)
/*
base-commit: 8d96f09e9245ddf80c1981476fcbac8c4bb4125f
--
gitgitgadget
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] win32: ensure that `localtime_r()` is declared even in i686 builds
2026-06-22 8:44 [PATCH] win32: ensure that `localtime_r()` is declared even in i686 builds Johannes Schindelin via GitGitGadget
@ 2026-06-22 9:11 ` Patrick Steinhardt
0 siblings, 0 replies; 2+ messages in thread
From: Patrick Steinhardt @ 2026-06-22 9:11 UTC (permalink / raw)
To: Johannes Schindelin via GitGitGadget; +Cc: git, Johannes Schindelin
On Mon, Jun 22, 2026 at 08:44:06AM +0000, Johannes Schindelin via GitGitGadget wrote:
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
>
> The `__MINGW64__` constant is defined, surprise, surprise, only when
> building for a 64-bit CPU architecture.
>
> Therefore using it as a guard to define `_POSIX_C_SOURCE` (so that
> `localtime_r()` is declared, among other functions) is not enough, we
> also need to check `__MINGW32__`.
>
> Technically, the latter constant is defined even for 64-bit builds. But
> let's make things a bit easier to understand by testing for both
> constants.
So it would suffice to use `__MINGW32__`? In any case, I agree that
making this explicit feels sane.
> Making it so fixes this compile warning (turned error in GCC v14.1):
>
> archive-zip.c: In function 'dos_time':
> archive-zip.c:612:9: error: implicit declaration of function 'localtime_r';
> did you mean 'localtime_s'? [-Wimplicit-function-declaration]
> 612 | localtime_r(&time, &tm);
> | ^~~~~~~~~~~
> | localtime_s
Makes sense. The function is available in C23, but we don't use it.
Otherwise, it's enabled with `_POSIX_C_SOURCE` according to [1].
> diff --git a/compat/posix.h b/compat/posix.h
> index 2f01564b0d..e2e794cad7 100644
> --- a/compat/posix.h
> +++ b/compat/posix.h
> @@ -56,7 +56,7 @@
> # define UNUSED
> #endif
>
> -#ifdef __MINGW64__
> +#if defined(__MINGW32__) || defined(__MINGW64__)
> #define _POSIX_C_SOURCE 1
> #elif defined(__sun__)
> /*
This looks nice and simple.
Thanks!
Patrick
[1]: https://man7.org/linux/man-pages/man3/ctime.3.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-22 9:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-22 8:44 [PATCH] win32: ensure that `localtime_r()` is declared even in i686 builds Johannes Schindelin via GitGitGadget
2026-06-22 9:11 ` Patrick Steinhardt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox