Skip to content

win32: ensure that localtime_r() is declared even in i686 builds#2157

Closed
dscho wants to merge 1 commit into
gitgitgadget:masterfrom
dscho:Fix-i686-build-with-GCC-v14
Closed

win32: ensure that localtime_r() is declared even in i686 builds#2157
dscho wants to merge 1 commit into
gitgitgadget:masterfrom
dscho:Fix-i686-build-with-GCC-v14

Conversation

@dscho

@dscho dscho commented Jun 22, 2026

Copy link
Copy Markdown
Member

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.

cc: Patrick Steinhardt ps@pks.im

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>
@dscho dscho self-assigned this Jun 22, 2026
@dscho

dscho commented Jun 22, 2026

Copy link
Copy Markdown
Member Author

/submit

@gitgitgadget

gitgitgadget Bot commented Jun 22, 2026

Copy link
Copy Markdown

Submitted as pull.2157.git.1782117847057.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-2157/dscho/Fix-i686-build-with-GCC-v14-v1

To fetch this version to local tag pr-2157/dscho/Fix-i686-build-with-GCC-v14-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-2157/dscho/Fix-i686-build-with-GCC-v14-v1

@gitgitgadget

gitgitgadget Bot commented Jun 23, 2026

Copy link
Copy Markdown

This patch series was integrated into seen via git@b0dcf92.

@gitgitgadget

gitgitgadget Bot commented Jun 23, 2026

Copy link
Copy Markdown

This patch series was integrated into master via git@b0dcf92.

@gitgitgadget

gitgitgadget Bot commented Jun 23, 2026

Copy link
Copy Markdown

This patch series was integrated into next via git@b0dcf92.

@gitgitgadget

gitgitgadget Bot commented Jun 23, 2026

Copy link
Copy Markdown

Congratulations! 🎉 Your patch series was merged into upstream via b0dcf92.

Note: this pull request will show as "Closed" rather than "Merged" because the merge happened in the upstream repository, not on GitHub. This is expected — your contribution has been accepted!

@dscho
dscho deleted the Fix-i686-build-with-GCC-v14 branch June 24, 2026 06:25
@gitgitgadget

gitgitgadget Bot commented Jul 6, 2026

Copy link
Copy Markdown

Patrick Steinhardt wrote on the Git mailing list (how to reply to this email):

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

@gitgitgadget

gitgitgadget Bot commented Jul 6, 2026

Copy link
Copy Markdown

User Patrick Steinhardt <ps@pks.im> has been added to the cc: list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant