{"thread":{"id":"65849","subject":"[PATCH] win32: ensure that `localtime_r()` is declared even in i686 builds","startedAt":"2026-06-22T08:44:09Z","lastAt":"2026-06-22T09:11:30Z","messageCount":2,"participants":["Johannes Schindelin via GitGitGadget","Patrick Steinhardt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"546141","messageId":"pull.2157.git.1782117847057.gitgitgadget@gmail.com","threadId":"65849","inReplyTo":null,"subject":"[PATCH] win32: ensure that `localtime_r()` is declared even in i686 builds","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-06-22T08:44:06Z","receivedAt":"2026-06-22T08:44:09Z","isPatch":true,"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nThe `__MINGW64__` constant is defined, surprise, surprise, only when\nbuilding for a 64-bit CPU architecture.\n\nTherefore using it as a guard to define `_POSIX_C_SOURCE` (so that\n`localtime_r()` is declared, among other functions) is not enough, we\nalso need to check `__MINGW32__`.\n\nTechnically, the latter constant is defined even for 64-bit builds. But\nlet's make things a bit easier to understand by testing for both\nconstants.\n\nMaking it so fixes this compile warning (turned error in GCC v14.1):\n\n  archive-zip.c: In function 'dos_time':\n  archive-zip.c:612:9: error: implicit declaration of function 'localtime_r';\n  did you mean 'localtime_s'? [-Wimplicit-function-declaration]\n    612 |         localtime_r(&time, &tm);\n        |         ^~~~~~~~~~~\n        |         localtime_s\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n    win32: ensure that localtime_r() is declared even in i686 builds\n    \n    Git for Windows plans on reducing the scope of its i686 support after\n    v2.55.0 even further, therefore this patch (which I had forgotten about)\n    needs to be in that version.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2157%2Fdscho%2FFix-i686-build-with-GCC-v14-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2157/dscho/Fix-i686-build-with-GCC-v14-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/2157\n\n compat/posix.h | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/compat/posix.h b/compat/posix.h\nindex 2f01564b0d..e2e794cad7 100644\n--- a/compat/posix.h\n+++ b/compat/posix.h\n@@ -56,7 +56,7 @@\n # define UNUSED\n #endif\n \n-#ifdef __MINGW64__\n+#if defined(__MINGW32__) || defined(__MINGW64__)\n #define _POSIX_C_SOURCE 1\n #elif defined(__sun__)\n  /*\n\nbase-commit: 8d96f09e9245ddf80c1981476fcbac8c4bb4125f\n-- \ngitgitgadget\n"},{"id":"546152","messageId":"ajj8OylK7jIMhFwp@pks.im","threadId":"65849","inReplyTo":"pull.2157.git.1782117847057.gitgitgadget@gmail.com","subject":"Re: [PATCH] win32: ensure that `localtime_r()` is declared even in i686 builds","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-06-22T09:11:23Z","receivedAt":"2026-06-22T09:11:30Z","isPatch":true,"body":"On Mon, Jun 22, 2026 at 08:44:06AM +0000, Johannes Schindelin via GitGitGadget wrote:\n> From: Johannes Schindelin <johannes.schindelin@gmx.de>\n> \n> The `__MINGW64__` constant is defined, surprise, surprise, only when\n> building for a 64-bit CPU architecture.\n> \n> Therefore using it as a guard to define `_POSIX_C_SOURCE` (so that\n> `localtime_r()` is declared, among other functions) is not enough, we\n> also need to check `__MINGW32__`.\n> \n> Technically, the latter constant is defined even for 64-bit builds. But\n> let's make things a bit easier to understand by testing for both\n> constants.\n\nSo it would suffice to use `__MINGW32__`? In any case, I agree that\nmaking this explicit feels sane.\n\n> Making it so fixes this compile warning (turned error in GCC v14.1):\n> \n>   archive-zip.c: In function 'dos_time':\n>   archive-zip.c:612:9: error: implicit declaration of function 'localtime_r';\n>   did you mean 'localtime_s'? [-Wimplicit-function-declaration]\n>     612 |         localtime_r(&time, &tm);\n>         |         ^~~~~~~~~~~\n>         |         localtime_s\n\nMakes sense. The function is available in C23, but we don't use it.\nOtherwise, it's enabled with `_POSIX_C_SOURCE` according to [1].\n\n> diff --git a/compat/posix.h b/compat/posix.h\n> index 2f01564b0d..e2e794cad7 100644\n> --- a/compat/posix.h\n> +++ b/compat/posix.h\n> @@ -56,7 +56,7 @@\n>  # define UNUSED\n>  #endif\n>  \n> -#ifdef __MINGW64__\n> +#if defined(__MINGW32__) || defined(__MINGW64__)\n>  #define _POSIX_C_SOURCE 1\n>  #elif defined(__sun__)\n>   /*\n\nThis looks nice and simple.\n\nThanks!\n\nPatrick\n\n[1]: https://man7.org/linux/man-pages/man3/ctime.3.html\n"}]}