From: Biswapriyo Nath <[email protected]>

Signed-off-by: Martin Storsjö <[email protected]>
---
Removed superfluous "const" on timespec_get parameters.

Moved the include of timeb.h to the head of time.h, to get struct
timespec declared before declaring timespec_get that uses it.

Added "#ifdef _UCRT" around the declarations (allowing compile-only
tests to detect if the declarations are available). Added such
a guard around the define of TIME_UTC too, to make sure that
define is available in sync with the rest.
---
 mingw-w64-headers/crt/sys/timeb.h | 10 ++++++++++
 mingw-w64-headers/crt/time.h      | 22 +++++++++++++++++++---
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/mingw-w64-headers/crt/sys/timeb.h 
b/mingw-w64-headers/crt/sys/timeb.h
index 7bfe98e0c..8f69a4648 100644
--- a/mingw-w64-headers/crt/sys/timeb.h
+++ b/mingw-w64-headers/crt/sys/timeb.h
@@ -86,6 +86,16 @@ extern "C" {
 #define _ftime _ftime32
 #endif
 
+struct _timespec32 {
+  __time32_t tv_sec;
+  long tv_nsec;
+};
+
+struct _timespec64 {
+  __time64_t tv_sec;
+  long tv_nsec;
+};
+
 #ifndef _TIMESPEC_DEFINED
 #define _TIMESPEC_DEFINED
 struct timespec {
diff --git a/mingw-w64-headers/crt/time.h b/mingw-w64-headers/crt/time.h
index ad4d52d11..b2a1631e2 100644
--- a/mingw-w64-headers/crt/time.h
+++ b/mingw-w64-headers/crt/time.h
@@ -21,6 +21,9 @@
 #endif /* _SECIMP */
 #endif /* defined(_CRTBLD) || defined(__LIBMSVCRT__) */
 
+/* Adding timespec definition.  */
+#include <sys/timeb.h>
+
 #pragma pack(push,_CRT_PACKING)
 
 #ifdef __cplusplus
@@ -109,6 +112,10 @@ extern "C" {
 
 #define CLOCKS_PER_SEC 1000
 
+#ifdef _UCRT
+#define TIME_UTC 1
+#endif
+
 #ifdef _UCRT
   _CRTIMP int *__cdecl __daylight(void);
   _CRTIMP long *__cdecl __dstbias(void);
@@ -146,6 +153,9 @@ extern "C" {
   _CRTIMP char *__cdecl _strtime(char *_Buffer) 
__MINGW_ATTRIB_DEPRECATED_SEC_WARN;
   _SECIMP errno_t __cdecl _strtime_s (char *_Buf ,size_t _SizeInBytes);
   _CRTIMP __time32_t __cdecl _time32(__time32_t *_Time);
+#ifdef _UCRT
+  _CRTIMP int __cdecl _timespec32_get(struct _timespec32 *_Ts, int _Base);
+#endif
   _CRTIMP __time32_t __cdecl _mktime32(struct tm *_Tm);
   _CRTIMP __time32_t __cdecl _mkgmtime32(struct tm *_Tm);
 
@@ -169,6 +179,9 @@ extern "C" {
   _CRTIMP __time64_t __cdecl _mktime64(struct tm *_Tm);
   _CRTIMP __time64_t __cdecl _mkgmtime64(struct tm *_Tm);
   _CRTIMP __time64_t __cdecl _time64(__time64_t *_Time);
+#ifdef _UCRT
+  _CRTIMP int __cdecl _timespec64_get(struct _timespec64 *_Ts, int _Base);
+#endif
   unsigned __cdecl _getsystime(struct tm *_Tm);
   unsigned __cdecl _setsystime(struct tm *_Tm,unsigned _MilliSec);
 
@@ -217,6 +230,9 @@ extern "C" {
 
 #ifdef _USE_32BIT_TIME_T
 static __inline time_t __CRTDECL time(time_t *_Time) { return _time32(_Time); }
+#ifdef _UCRT
+static __inline int __CRTDECL timespec_get(struct timespec* _Ts, int _Base) { 
return _timespec32_get((struct _timespec32*)_Ts, _Base); }
+#endif
 static __inline double __CRTDECL difftime(time_t _Time1,time_t _Time2)  { 
return _difftime32(_Time1,_Time2); }
 static __inline struct tm *__CRTDECL localtime(const time_t *_Time) { return 
_localtime32(_Time); }
 static __inline errno_t __CRTDECL localtime_s(struct tm *_Tm,const time_t 
*_Time) { return _localtime32_s(_Tm,_Time); }
@@ -228,6 +244,9 @@ static __inline time_t __CRTDECL mktime(struct tm *_Tm) { 
return _mktime32(_Tm);
 static __inline time_t __CRTDECL _mkgmtime(struct tm *_Tm) { return 
_mkgmtime32(_Tm); }
 #else
 static __inline time_t __CRTDECL time(time_t *_Time) { return _time64(_Time); }
+#ifdef _UCRT
+static __inline int __CRTDECL timespec_get(struct timespec* _Ts, int _Base) { 
return _timespec64_get((struct _timespec64*)_Ts, _Base); }
+#endif
 static __inline double __CRTDECL difftime(time_t _Time1,time_t _Time2) { 
return _difftime64(_Time1,_Time2); }
 static __inline struct tm *__CRTDECL localtime(const time_t *_Time) { return 
_localtime64(_Time); }
 static __inline errno_t __CRTDECL localtime_s(struct tm *_Tm,const time_t 
*_Time) { return _localtime64_s(_Tm,_Time); }
@@ -296,9 +315,6 @@ __forceinline char *__CRTDECL asctime_r(const struct tm 
*_Tm, char * _Str) {
 }
 #endif
 
-/* Adding timespec definition.  */
-#include <sys/timeb.h>
-
 /* POSIX 2008 says clock_gettime and timespec are defined in time.h header,
    but other systems - like Linux, Solaris, etc - tend to declare such
    recent extensions only if the following guards are met.  */
-- 
2.25.1



_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to