Re: [Mingw-w64-public] [PATCH] Cleanup and optimize gettimeofday
在 2026-9-10 15:59, Zhongteng Gui 写道: On 2026/09/10 15:46, Martin Storsjö wrote: I think the simplest and most pragmatic workaround would be to reinstate at least the "#define _TIMEZONE_DEFINED". We could also reinstate the ifdefs around it, to avoid conflicts if user headers may have defined it before us. But we can at least avoid duplicating it between the two headers, if one of them always include the other one. I think this is reasonable, I didn't expect that so many downstream projects define struct timezone themselves, considering that MSVC doesn't provide this macro. Attached a new patch that restore _TIMEZONE_DEFINED. OK. I have pushed this patch now. -- Best regards, LIU Hao OpenPGP_signature.asc Description: OpenPGP digital signature ___ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [PATCH] Cleanup and optimize gettimeofday
在 2026-9-10 15:46, Martin Storsjö 写道: I think the simplest and most pragmatic workaround would be to reinstate at least the "#define _TIMEZONE_DEFINED". We could also reinstate the ifdefs around it, to avoid conflicts if user headers may have defined it before us. But we can at least avoid duplicating it between the two headers, if one of them always include the other one. Sounds reasonable; since Microsoft headers don't define this structure, it makes sense for a user to define their own, and a macro will be useful. -- Best regards, LIU Hao OpenPGP_signature.asc Description: OpenPGP digital signature ___ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [PATCH] Cleanup and optimize gettimeofday
On Wed, 9 Sep 2026, LIU Hao wrote:
Thanks. Pushed now.
These changes broke building the "srt" library, thus breaking building
VLC.
The srt library contains a header,
https://github.com/Haivision/srt/blob/v1.5.7/common/win/wintime.h#L24-L31,
which contains this:
#ifndef _TIMEZONE_DEFINED /* also in sys/time.h */
#define _TIMEZONE_DEFINED
struct timezone
{
int tz_minuteswest; /* minutes W of Greenwich */
int tz_dsttime; /* type of dst correction */
};
#endif
After our headers now no longer define _TIMEZONE_DEFINED, we end up with a
duplicate definition of the struct here.
I think the simplest and most pragmatic workaround would be to reinstate
at least the "#define _TIMEZONE_DEFINED". We could also reinstate the
ifdefs around it, to avoid conflicts if user headers may have defined it
before us. But we can at least avoid duplicating it between the two
headers, if one of them always include the other one.
// Martin
___
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [PATCH] Cleanup and optimize gettimeofday
On 2026/09/09 14:52, LIU Hao wrote:
> 在 2026-9-9 14:49, Zhongteng Gui 写道:
>> This is indeed an issue. Previously I considered to provide
>> `mingw_gettimeofday`, and forward `gettimeofday` to it. But considering that
>> some packages may use autotools to detect `gettimeofday` (including
>> winpthreads), and autotools doesn't use header file, so I finally chose to
>> provide `gettimeofday` and forward `mingw_gettimeofday`.
>>
>> Maybe we could solve this by the following, and removes __MINGW_ASM_CALL.
>>
>> ```
>> // in gettimeofday.c
>> int gettimeofday(struct timeval* tv, struct timezone* tz) {
>> return mingw_gettimeofday(tv, tz);
>> }
>>
>> int mingw_gettimeofday(struct timeval* tv, struct timezone* tz) {
>> // Actual logic
>> }
>> ```
>>
>> If this is ok, I'll update this together with the above 2 fixes.
> looks fine; but the second parameter of `gettimeofday` should be `void*`.
>
Sorry for the typo. Fixed altogether in v3 patches.
From 190a56d14e25c243a94cd15297858719841a03fe Mon Sep 17 00:00:00 2001
From: Zhongteng Gui
Date: Fri, 4 Sep 2026 22:02:53 +0800
Subject: [PATCH v3 1/2] headers: crt: Clean up time.h and sys/time.h
sys/time.h always include time.h, so no need to define timezone and
mingw_gettimeofday itself.
Use reserved parameter name for mingw_gettimeofday.
Remove _TIMEZONE_DEFINED and _GETTIMEOFDAY_DEFINED.
Signed-off-by: Zhongteng Gui
---
mingw-w64-headers/crt/sys/time.h | 36 +++-
mingw-w64-headers/crt/time.h | 5 +
2 files changed, 4 insertions(+), 37 deletions(-)
diff --git a/mingw-w64-headers/crt/sys/time.h b/mingw-w64-headers/crt/sys/time.h
index 9ef3fd3dd..56a093156 100644
--- a/mingw-w64-headers/crt/sys/time.h
+++ b/mingw-w64-headers/crt/sys/time.h
@@ -11,40 +11,10 @@
_CRT_BEGIN_C_HEADER
-#include <_timeval.h>
-
-#ifndef _TIMEZONE_DEFINED /* also in sys/time.h */
-#define _TIMEZONE_DEFINED
-/* Provided for compatibility with code that assumes that
- the presence of gettimeofday function implies a definition
- of struct timezone. */
-struct timezone
-{
- int tz_minuteswest; /* of Greenwich */
- int tz_dsttime; /* type of dst correction to apply */
-};
-
- extern int __cdecl mingw_gettimeofday (struct timeval *p, struct timezone
*z);
-
-#endif /* _TIMEZONE_DEFINED */
-
-/*
- Implementation as per:
- The Open Group Base Specifications, Issue 6
- IEEE Std 1003.1, 2004 Edition
-
- The timezone pointer arg is ignored. Errors are ignored.
-*/
-#ifndef _GETTIMEOFDAY_DEFINED
-#define _GETTIMEOFDAY_DEFINED
-int __cdecl gettimeofday(struct timeval *__restrict__,
- void *__restrict__ /* tzp (unused) */);
-#endif
+/* TODO: POSIX.1-2008 marked it as obsolete, and POSIX.1-2024 removed it. */
+/* libiberty.h requires the second argument to be void* instead of struct
timezone* */
+int __cdecl gettimeofday(struct timeval* __restrict__ _Tv, void* __restrict__
_Tz);
_CRT_END_C_HEADER
-/* Adding timespec definition. */
-#include
-
-
#endif /* _SYS_TIME_H_ */
diff --git a/mingw-w64-headers/crt/time.h b/mingw-w64-headers/crt/time.h
index 2a8e39223..3d69e7c76 100644
--- a/mingw-w64-headers/crt/time.h
+++ b/mingw-w64-headers/crt/time.h
@@ -163,15 +163,12 @@ time_t __CRTDECL _mkgmtime(struct tm *_Tm)
__MINGW_ASM_CALL(_mkgmtime64);
#include <_timeval.h>
-#ifndef _TIMEZONE_DEFINED /* also in sys/time.h */
-#define _TIMEZONE_DEFINED
struct timezone {
int tz_minuteswest;
int tz_dsttime;
};
- extern int __cdecl mingw_gettimeofday (struct timeval *p, struct timezone
*z);
-#endif /* _TIMEZONE_DEFINED */
+int __cdecl mingw_gettimeofday(struct timeval* _Tv, struct timezone* _Tz);
#if defined(_POSIX_C_SOURCE) && !defined(_POSIX_THREAD_SAFE_FUNCTIONS)
#define _POSIX_THREAD_SAFE_FUNCTIONS 200112L
--
2.55.0.windows.5
From ba4a136e0ce276a6f271690c7f3fdf307040890c Mon Sep 17 00:00:00 2001
From: Zhongteng Gui
Date: Fri, 4 Sep 2026 22:10:10 +0800
Subject: [PATCH v3 2/2] crt: gettimeofday.c: Optimize implemention
Forward gettimeofday to mingw_gettimeofday.
Merge getntptimeofday into gettimeofday and remove redundant conditions.
Signed-off-by: Zhongteng Gui
---
mingw-w64-crt/misc/gettimeofday.c | 60 ++-
1 file changed, 19 insertions(+), 41 deletions(-)
diff --git a/mingw-w64-crt/misc/gettimeofday.c
b/mingw-w64-crt/misc/gettimeofday.c
index 968f3ed33..0e1c61b91 100644
--- a/mingw-w64-crt/misc/gettimeofday.c
+++ b/mingw-w64-crt/misc/gettimeofday.c
@@ -5,42 +5,37 @@
*/
#include
#include
-#include
-#include
#include
#define FILETIME_1970 1164447360ull /* seconds between 1/1/1601 and
1/1/1970 */
#define HECTONANOSEC_PER_SEC 1000ull
-int getntptimeofday (struct timespec *, struct timezone *);
-
-int getntptimeofday (struct timespec *tp, struct timezone *z)
+int __cdecl mingw_gettimeofday(struct timeval* __restrict__ _Tv, struct
timezone* __restrict__ _Tz)
{
- int res = 0;
union {
unsigned long long ns100; /*time since
Re: [Mingw-w64-public] [PATCH] Cleanup and optimize gettimeofday
On 2026/09/09 14:14, LIU Hao wrote:
> 在 2026-9-5 01:12, Zhongteng Gui 写道:
>> On 2026/09/04 22:52, Zhongteng Gui wrote:
>>> Hi, here're 2 patches about cleanup and optimize gettimeofday (and related
>>> stuff).
>>>
>>> This change is a bit huge, and I'm not very sure about some parts, e.g.
>>>
>>> 1. Originally, we provide `int gettimeofday(struct timeval*, void*)`, while
>>> POSIX expects `int gettimeofday(struct timeval*, struct timezone*)`. It's
>>> noteworthy that switching to POSIX will breaks GCC without special handling.
>>> because libiberty.h bundled by GCC specially checked for __MINGW32__, and
>>> declares gettimeofday with `void*` arg type, which fails with
>>> -Wstrict-prototypes. But keeping `void*` is semantically wrong, as we
>>> actually
>>> set timezone if nonnull.
>>>
>>> 2. Should we conditionally expose gettimeofday? It is marked as obsolete in
>>> POSIX.1-2008 and removed in POSIX.1-2024.
>
> It's just not required any more, but legacy code still wants to call it.
>
>
>>> 3. Originally, gettimeofday assumed "struct timeval*" to be nonnull, and
>>> didn't
>>> check this. Should we keep this as is, or check it and return -1 if NULL?
>
> I'd expect that a null pointer be ignored, like on Linux.
>
>
>> +int __cdecl mingw_gettimeofday(struct timeval* _tv, struct timezone* _tz)
>> __MINGW_ASM_CALL(gettimeofday);
>
>
> The parameter names should be `_Tv` and `_Tz`. An identifier with one
> underscore
> followed by a lowercase letter is reserved only in global namespace.
Ok, I'll send an updated patch later with the above 2 issues fixed.
>
> And I suspect this can result in infinite recursion if a user has
>
> int
> gettimeofday(struct timeval* tv, struct timezone* tz)
> {
> return mingw_gettimeofday(tv, tz); // calls `gettimeofday`
> }
>
>
This is indeed an issue. Previously I considered to provide
`mingw_gettimeofday`, and forward `gettimeofday` to it. But considering that
some packages may use autotools to detect `gettimeofday` (including
winpthreads), and autotools doesn't use header file, so I finally chose to
provide `gettimeofday` and forward `mingw_gettimeofday`.
Maybe we could solve this by the following, and removes __MINGW_ASM_CALL.
```
// in gettimeofday.c
int gettimeofday(struct timeval* tv, struct timezone* tz) {
return mingw_gettimeofday(tv, tz);
}
int mingw_gettimeofday(struct timeval* tv, struct timezone* tz) {
// Actual logic
}
```
If this is ok, I'll update this together with the above 2 fixes.
___
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [PATCH] Cleanup and optimize gettimeofday
在 2026-9-9 15:55, Zhongteng Gui 写道:
On 2026/09/09 14:52, LIU Hao wrote:
在 2026-9-9 14:49, Zhongteng Gui 写道:
This is indeed an issue. Previously I considered to provide
`mingw_gettimeofday`, and forward `gettimeofday` to it. But considering that
some packages may use autotools to detect `gettimeofday` (including
winpthreads), and autotools doesn't use header file, so I finally chose to
provide `gettimeofday` and forward `mingw_gettimeofday`.
Maybe we could solve this by the following, and removes __MINGW_ASM_CALL.
```
// in gettimeofday.c
int gettimeofday(struct timeval* tv, struct timezone* tz) {
return mingw_gettimeofday(tv, tz);
}
int mingw_gettimeofday(struct timeval* tv, struct timezone* tz) {
// Actual logic
}
```
If this is ok, I'll update this together with the above 2 fixes.
looks fine; but the second parameter of `gettimeofday` should be `void*`.
Sorry for the typo. Fixed altogether in v3 patches.
Thanks. Pushed now.
--
Best regards,
LIU Hao
OpenPGP_signature.asc
Description: OpenPGP digital signature
___
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [PATCH] Cleanup and optimize gettimeofday
在 2026-9-9 14:49, Zhongteng Gui 写道:
This is indeed an issue. Previously I considered to provide
`mingw_gettimeofday`, and forward `gettimeofday` to it. But considering that
some packages may use autotools to detect `gettimeofday` (including
winpthreads), and autotools doesn't use header file, so I finally chose to
provide `gettimeofday` and forward `mingw_gettimeofday`.
Maybe we could solve this by the following, and removes __MINGW_ASM_CALL.
```
// in gettimeofday.c
int gettimeofday(struct timeval* tv, struct timezone* tz) {
return mingw_gettimeofday(tv, tz);
}
int mingw_gettimeofday(struct timeval* tv, struct timezone* tz) {
// Actual logic
}
```
If this is ok, I'll update this together with the above 2 fixes.
looks fine; but the second parameter of `gettimeofday` should be `void*`.
--
Best regards,
LIU Hao
OpenPGP_signature.asc
Description: OpenPGP digital signature
___
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [PATCH] Cleanup and optimize gettimeofday
在 2026-9-5 01:12, Zhongteng Gui 写道:
On 2026/09/04 22:52, Zhongteng Gui wrote:
Hi, here're 2 patches about cleanup and optimize gettimeofday (and related
stuff).
This change is a bit huge, and I'm not very sure about some parts, e.g.
1. Originally, we provide `int gettimeofday(struct timeval*, void*)`, while
POSIX expects `int gettimeofday(struct timeval*, struct timezone*)`. It's
noteworthy that switching to POSIX will breaks GCC without special handling.
because libiberty.h bundled by GCC specially checked for __MINGW32__, and
declares gettimeofday with `void*` arg type, which fails with
-Wstrict-prototypes. But keeping `void*` is semantically wrong, as we actually
set timezone if nonnull.
2. Should we conditionally expose gettimeofday? It is marked as obsolete in
POSIX.1-2008 and removed in POSIX.1-2024.
It's just not required any more, but legacy code still wants to call it.
3. Originally, gettimeofday assumed "struct timeval*" to be nonnull, and didn't
check this. Should we keep this as is, or check it and return -1 if NULL?
I'd expect that a null pointer be ignored, like on Linux.
+int __cdecl mingw_gettimeofday(struct timeval* _tv, struct timezone* _tz)
__MINGW_ASM_CALL(gettimeofday);
The parameter names should be `_Tv` and `_Tz`. An identifier with one underscore followed by a lowercase
letter is reserved only in global namespace.
And I suspect this can result in infinite recursion if a user has
int
gettimeofday(struct timeval* tv, struct timezone* tz)
{
return mingw_gettimeofday(tv, tz); // calls `gettimeofday`
}
--
Best regards,
LIU Hao
OpenPGP_signature.asc
Description: OpenPGP digital signature
___
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [PATCH] Cleanup and optimize gettimeofday
Zhongteng Gui wrote: > On 2026/09/05 11:03, Kirill Makurin wrote: >> Zhongteng Gui wrote: >> >>> 1. Originally, we provide `int gettimeofday(struct timeval*, void*)`, while >>> POSIX expects `int gettimeofday(struct timeval*, struct timezone*)`. It's >>> noteworthy that switching to POSIX will breaks GCC without special handling. >>> because libiberty.h bundled by GCC specially checked for __MINGW32__, and >>> declares gettimeofday with `void*` arg type, which fails with >>> -Wstrict-prototypes. But keeping `void*` is semantically wrong, as we >>> actually >>> set timezone if nonnull. >> >> Are you sure? 2018 edition of POSIX specification[1] declares it as `int >> gettimeofday(struct timeval *restrict tp, void *restrict tzp)`. >> >> It also says: >> >> ``` >> If tzp is not a null pointer, the behavior is unspecified. >> ``` >> >> And so, POSIX says nothing about `struct timezone`, what it is and how to >> use it. > > I got the impression from > https://www.man7.org/linux/man-pages/man2/gettimeofday.2.html I had this happen to me a few times as well. These man pages describe Linux behavior and may sometimes disagree with POSIX specification. OTOH, there are also man pages which describe POSIX behavior instead. You can easily distinguish them: Linux ones have "Library Functions Manual" at the header. > Seemes that POSIX uses `void*`, while glibc uses `struct timezone*`. I think many historical systems (Unix, BSDs, Linux) are likely to have `struct timezone*` because they actually used it in one way or another, or simply were following older versions of POSIX. - Kirill Makurin ___ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [PATCH] Cleanup and optimize gettimeofday
On 2026/09/05 11:03, Kirill Makurin wrote: > Zhongteng Gui wrote: > >> 1. Originally, we provide `int gettimeofday(struct timeval*, void*)`, while >> POSIX expects `int gettimeofday(struct timeval*, struct timezone*)`. It's >> noteworthy that switching to POSIX will breaks GCC without special handling. >> because libiberty.h bundled by GCC specially checked for __MINGW32__, and >> declares gettimeofday with `void*` arg type, which fails with >> -Wstrict-prototypes. But keeping `void*` is semantically wrong, as we >> actually >> set timezone if nonnull. > > Are you sure? 2018 edition of POSIX specification[1] declares it as `int > gettimeofday(struct timeval *restrict tp, void *restrict tzp)`. > > It also says: > > ``` > If tzp is not a null pointer, the behavior is unspecified. > ``` > > And so, POSIX says nothing about `struct timezone`, what it is and how to use > it. I got the impression from https://www.man7.org/linux/man-pages/man2/gettimeofday.2.html Seemes that POSIX uses `void*`, while glibc uses `struct timezone*`. > >> 2. Should we conditionally expose gettimeofday? It is marked as obsolete in >> POSIX.1-2008 and removed in POSIX.1-2024. > > I see no reason to do this; I think this would an unnecessary complication. > Maybe `attribute((deprecated))` is an option, but IMO, it creates more > annoyance than benefits. > >> 3. Originally, gettimeofday assumed "struct timeval*" to be nonnull, and >> didn't >> check this. Should we keep this as is, or check it and return -1 if NULL? > > I have a few changes to `pthread_mutex_timedlock` in my winpthreads mutex > changes I sent to the list, and POSIX does not say anything about `struct > timespec` argument being NULL. So, for both cases, my assumption here is that > NULL is not a valid value for the parameter, and application must never pass > it, and so checking for it is unnecessary. > > - Kirill Makurin > > [1] > https://pubs.opengroup.org/onlinepubs/9699919799/functions/gettimeofday.html > ___ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [PATCH] Cleanup and optimize gettimeofday
Zhongteng Gui wrote: > 1. Originally, we provide `int gettimeofday(struct timeval*, void*)`, while > POSIX expects `int gettimeofday(struct timeval*, struct timezone*)`. It's > noteworthy that switching to POSIX will breaks GCC without special handling. > because libiberty.h bundled by GCC specially checked for __MINGW32__, and > declares gettimeofday with `void*` arg type, which fails with > -Wstrict-prototypes. But keeping `void*` is semantically wrong, as we actually > set timezone if nonnull. Are you sure? 2018 edition of POSIX specification[1] declares it as `int gettimeofday(struct timeval *restrict tp, void *restrict tzp)`. It also says: ``` If tzp is not a null pointer, the behavior is unspecified. ``` And so, POSIX says nothing about `struct timezone`, what it is and how to use it. > 2. Should we conditionally expose gettimeofday? It is marked as obsolete in > POSIX.1-2008 and removed in POSIX.1-2024. I see no reason to do this; I think this would an unnecessary complication. Maybe `attribute((deprecated))` is an option, but IMO, it creates more annoyance than benefits. > 3. Originally, gettimeofday assumed "struct timeval*" to be nonnull, and > didn't > check this. Should we keep this as is, or check it and return -1 if NULL? I have a few changes to `pthread_mutex_timedlock` in my winpthreads mutex changes I sent to the list, and POSIX does not say anything about `struct timespec` argument being NULL. So, for both cases, my assumption here is that NULL is not a valid value for the parameter, and application must never pass it, and so checking for it is unnecessary. - Kirill Makurin [1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/gettimeofday.html ___ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
