| 1 |
/** |
| 2 |
* This file has no copyright assigned and is placed in the Public Domain. |
| 3 |
* This file is part of the mingw-w64 runtime package. |
| 4 |
* No warranty is given; refer to the file DISCLAIMER.PD within this package. |
| 5 |
*/ |
| 6 |
#ifndef _TIME_H_ |
| 7 |
#define _TIME_H_ |
| 8 |
|
| 9 |
#include <crtdefs.h> |
| 10 |
|
| 11 |
#ifndef _WIN32 |
| 12 |
#error Only Win32 target is supported! |
| 13 |
#endif |
| 14 |
|
| 15 |
#if defined(__LIBMSVCRT__) |
| 16 |
/* When building mingw-w64, this should be blank. */ |
| 17 |
#define _SECIMP |
| 18 |
#else |
| 19 |
#ifndef _SECIMP |
| 20 |
#define _SECIMP __declspec(dllimport) |
| 21 |
#endif /* _SECIMP */ |
| 22 |
#endif /* defined(__LIBMSVCRT__) */ |
| 23 |
|
| 24 |
/* Adding timespec definition. */ |
| 25 |
#include <sys/timeb.h> |
| 26 |
|
| 27 |
#pragma pack(push,_CRT_PACKING) |
| 28 |
|
| 29 |
#ifdef __cplusplus |
| 30 |
extern "C" { |
| 31 |
#endif |
| 32 |
|
| 33 |
#ifndef _CRTIMP |
| 34 |
#define _CRTIMP __declspec(dllimport) |
| 35 |
#endif |
| 36 |
|
| 37 |
#ifndef _WCHAR_T_DEFINED |
| 38 |
#define _WCHAR_T_DEFINED |
| 39 |
typedef unsigned short wchar_t; |
| 40 |
#endif |
| 41 |
|
| 42 |
#ifndef _TIME32_T_DEFINED |
| 43 |
#define _TIME32_T_DEFINED |
| 44 |
typedef long __time32_t; |
| 45 |
#endif |
| 46 |
|
| 47 |
#ifndef _TIME64_T_DEFINED |
| 48 |
#define _TIME64_T_DEFINED |
| 49 |
__MINGW_EXTENSION typedef __int64 __time64_t; |
| 50 |
#endif |
| 51 |
|
| 52 |
#ifndef _TIME_T_DEFINED |
| 53 |
#define _TIME_T_DEFINED |
| 54 |
#ifdef _USE_32BIT_TIME_T |
| 55 |
typedef __time32_t time_t; |
| 56 |
#else |
| 57 |
typedef __time64_t time_t; |
| 58 |
#endif |
| 59 |
#endif |
| 60 |
|
| 61 |
#ifndef _CLOCK_T_DEFINED |
| 62 |
#define _CLOCK_T_DEFINED |
| 63 |
typedef long clock_t; |
| 64 |
#endif |
| 65 |
|
| 66 |
#ifndef _SIZE_T_DEFINED |
| 67 |
#define _SIZE_T_DEFINED |
| 68 |
#undef size_t |
| 69 |
#ifdef _WIN64 |
| 70 |
__MINGW_EXTENSION typedef unsigned __int64 size_t; |
| 71 |
#else |
| 72 |
typedef unsigned int size_t; |
| 73 |
#endif |
| 74 |
#endif |
| 75 |
|
| 76 |
#ifndef _SSIZE_T_DEFINED |
| 77 |
#define _SSIZE_T_DEFINED |
| 78 |
#undef ssize_t |
| 79 |
#ifdef _WIN64 |
| 80 |
__MINGW_EXTENSION typedef __int64 ssize_t; |
| 81 |
#else |
| 82 |
typedef int ssize_t; |
| 83 |
#endif |
| 84 |
#endif |
| 85 |
|
| 86 |
#ifndef NULL |
| 87 |
#ifdef __cplusplus |
| 88 |
#ifndef _WIN64 |
| 89 |
#define NULL 0 |
| 90 |
#else |
| 91 |
#define NULL 0LL |
| 92 |
#endif /* W64 */ |
| 93 |
#else |
| 94 |
#define NULL ((void *)0) |
| 95 |
#endif |
| 96 |
#endif |
| 97 |
|
| 98 |
#ifndef _TM_DEFINED |
| 99 |
#define _TM_DEFINED |
| 100 |
struct tm { |
| 101 |
int tm_sec; |
| 102 |
int tm_min; |
| 103 |
int tm_hour; |
| 104 |
int tm_mday; |
| 105 |
int tm_mon; |
| 106 |
int tm_year; |
| 107 |
int tm_wday; |
| 108 |
int tm_yday; |
| 109 |
int tm_isdst; |
| 110 |
}; |
| 111 |
#endif |
| 112 |
|
| 113 |
#define CLOCKS_PER_SEC 1000 |
| 114 |
|
| 115 |
#ifdef _UCRT |
| 116 |
#define TIME_UTC 1 |
| 117 |
#endif |
| 118 |
|
| 119 |
_CRTIMP int *__cdecl __daylight(void); |
| 120 |
_CRTIMP long *__cdecl __dstbias(void); |
| 121 |
_CRTIMP long *__cdecl __timezone(void); |
| 122 |
_CRTIMP char **__cdecl __tzname(void); |
| 123 |
#define _daylight (* __daylight()) |
| 124 |
#define _dstbias (* __dstbias()) |
| 125 |
#define _timezone (* __timezone()) |
| 126 |
#define _tzname (__tzname()) |
| 127 |
|
| 128 |
#undef __MINGW_STRFTIME_FORMAT |
| 129 |
|
| 130 |
#if defined(__clang__) |
| 131 |
#define __MINGW_STRFTIME_FORMAT strftime |
| 132 |
#elif defined(_UCRT) |
| 133 |
#define __MINGW_STRFTIME_FORMAT gnu_strftime |
| 134 |
#else |
| 135 |
#define __MINGW_STRFTIME_FORMAT ms_strftime |
| 136 |
#endif |
| 137 |
|
| 138 |
_CRTIMP errno_t __cdecl _get_daylight(int *_Daylight); |
| 139 |
_CRTIMP errno_t __cdecl _get_dstbias(long *_Daylight_savings_bias); |
| 140 |
_CRTIMP errno_t __cdecl _get_timezone(long *_Timezone); |
| 141 |
_CRTIMP errno_t __cdecl _get_tzname(size_t *_ReturnValue,char *_Buffer,size_t _SizeInBytes,int _Index); |
| 142 |
char *__cdecl asctime(const struct tm *_Tm) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; |
| 143 |
_SECIMP errno_t __cdecl asctime_s (char *_Buf,size_t _SizeInWords,const struct tm *_Tm); |
| 144 |
_CRTIMP char *__cdecl _ctime32(const __time32_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; |
| 145 |
_SECIMP errno_t __cdecl _ctime32_s (char *_Buf,size_t _SizeInBytes,const __time32_t *_Time); |
| 146 |
clock_t __cdecl clock(void); |
| 147 |
_CRTIMP double __cdecl _difftime32(__time32_t _Time1,__time32_t _Time2); |
| 148 |
_CRTIMP struct tm *__cdecl _gmtime32(const __time32_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; |
| 149 |
_SECIMP errno_t __cdecl _gmtime32_s (struct tm *_Tm,const __time32_t *_Time); |
| 150 |
_CRTIMP struct tm *__cdecl _localtime32(const __time32_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; |
| 151 |
_SECIMP errno_t __cdecl _localtime32_s (struct tm *_Tm,const __time32_t *_Time); |
| 152 |
size_t __cdecl strftime(char * __restrict__ _Buf,size_t _SizeInBytes,const char * __restrict__ _Format,const struct tm * __restrict__ _Tm) __attribute__((__format__ (__MINGW_STRFTIME_FORMAT, 3, 0))); |
| 153 |
_CRTIMP size_t __cdecl _strftime_l(char * __restrict__ _Buf,size_t _Max_size,const char * __restrict__ _Format,const struct tm * __restrict__ _Tm,_locale_t _Locale); |
| 154 |
_CRTIMP char *__cdecl _strdate(char *_Buffer) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; |
| 155 |
_SECIMP errno_t __cdecl _strdate_s (char *_Buf,size_t _SizeInBytes); |
| 156 |
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_0(errno_t, _strdate_s, char, _Str) |
| 157 |
_CRTIMP char *__cdecl _strtime(char *_Buffer) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; |
| 158 |
_SECIMP errno_t __cdecl _strtime_s (char *_Buf ,size_t _SizeInBytes); |
| 159 |
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_0(errno_t, _strtime_s, char, _Str) |
| 160 |
_CRTIMP __time32_t __cdecl _time32(__time32_t *_Time); |
| 161 |
#ifdef _UCRT |
| 162 |
_CRTIMP int __cdecl _timespec32_get(struct _timespec32 *_Ts, int _Base); |
| 163 |
#endif |
| 164 |
_CRTIMP __time32_t __cdecl _mktime32(struct tm *_Tm); |
| 165 |
_CRTIMP __time32_t __cdecl _mkgmtime32(struct tm *_Tm); |
| 166 |
|
| 167 |
#if defined (_POSIX_) || defined(__GNUC__) |
| 168 |
void __cdecl tzset(void) __MINGW_ATTRIB_DEPRECATED_MSVC2005; |
| 169 |
#endif |
| 170 |
#if !defined (_POSIX_) |
| 171 |
#ifndef _UCRT |
| 172 |
_CRTIMP |
| 173 |
#endif |
| 174 |
void __cdecl _tzset(void); |
| 175 |
#endif |
| 176 |
|
| 177 |
_CRTIMP double __cdecl _difftime64(__time64_t _Time1,__time64_t _Time2); |
| 178 |
_CRTIMP char *__cdecl _ctime64(const __time64_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; |
| 179 |
_SECIMP errno_t __cdecl _ctime64_s (char *_Buf,size_t _SizeInBytes,const __time64_t *_Time); |
| 180 |
_CRTIMP struct tm *__cdecl _gmtime64(const __time64_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; |
| 181 |
_SECIMP errno_t __cdecl _gmtime64_s (struct tm *_Tm,const __time64_t *_Time); |
| 182 |
_CRTIMP struct tm *__cdecl _localtime64(const __time64_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; |
| 183 |
_SECIMP errno_t __cdecl _localtime64_s (struct tm *_Tm,const __time64_t *_Time); |
| 184 |
_CRTIMP __time64_t __cdecl _mktime64(struct tm *_Tm); |
| 185 |
_CRTIMP __time64_t __cdecl _mkgmtime64(struct tm *_Tm); |
| 186 |
_CRTIMP __time64_t __cdecl _time64(__time64_t *_Time); |
| 187 |
#ifdef _UCRT |
| 188 |
_CRTIMP int __cdecl _timespec64_get(struct _timespec64 *_Ts, int _Base); |
| 189 |
#endif |
| 190 |
unsigned __cdecl _getsystime(struct tm *_Tm); |
| 191 |
unsigned __cdecl _setsystime(struct tm *_Tm,unsigned _MilliSec); |
| 192 |
|
| 193 |
#ifndef _WTIME_DEFINED |
| 194 |
_CRTIMP wchar_t *__cdecl _wasctime(const struct tm *_Tm); |
| 195 |
_SECIMP errno_t __cdecl _wasctime_s (wchar_t *_Buf,size_t _SizeInWords,const struct tm *_Tm); |
| 196 |
wchar_t *__cdecl _wctime32(const __time32_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; |
| 197 |
_SECIMP errno_t __cdecl _wctime32_s (wchar_t *_Buf,size_t _SizeInWords,const __time32_t *_Time); |
| 198 |
size_t __cdecl wcsftime(wchar_t * __restrict__ _Buf,size_t _SizeInWords,const wchar_t * __restrict__ _Format,const struct tm * __restrict__ _Tm); |
| 199 |
_CRTIMP size_t __cdecl _wcsftime_l(wchar_t * __restrict__ _Buf,size_t _SizeInWords,const wchar_t * __restrict__ _Format,const struct tm * __restrict__ _Tm,_locale_t _Locale); |
| 200 |
_CRTIMP wchar_t *__cdecl _wstrdate(wchar_t *_Buffer) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; |
| 201 |
_SECIMP errno_t __cdecl _wstrdate_s (wchar_t *_Buf,size_t _SizeInWords); |
| 202 |
_CRTIMP wchar_t *__cdecl _wstrtime(wchar_t *_Buffer) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; |
| 203 |
_SECIMP errno_t __cdecl _wstrtime_s (wchar_t *_Buf,size_t _SizeInWords); |
| 204 |
_CRTIMP wchar_t *__cdecl _wctime64(const __time64_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; |
| 205 |
_SECIMP errno_t __cdecl _wctime64_s (wchar_t *_Buf,size_t _SizeInWords,const __time64_t *_Time); |
| 206 |
|
| 207 |
#if !defined (RC_INVOKED) && !defined (_INC_WTIME_INL) |
| 208 |
#define _INC_WTIME_INL |
| 209 |
#ifndef _USE_32BIT_TIME_T |
| 210 |
wchar_t *__cdecl _wctime(const time_t *_Time) __MINGW_ASM_CALL(_wctime64) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; |
| 211 |
#else |
| 212 |
wchar_t *__cdecl _wctime(const time_t *_Time) __MINGW_ASM_CALL(_wctime32) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; |
| 213 |
#endif |
| 214 |
#endif |
| 215 |
|
| 216 |
#if !defined (RC_INVOKED) && !defined (_INC_WTIME_S_INL) |
| 217 |
#define _INC_WTIME_S_INL |
| 218 |
#ifndef _USE_32BIT_TIME_T |
| 219 |
errno_t __cdecl _wctime_s (wchar_t *_Buffer,size_t _SizeInWords,const time_t *_Time) __MINGW_ASM_CALL(_wctime64_s); |
| 220 |
#else |
| 221 |
errno_t __cdecl _wctime_s (wchar_t *_Buffer,size_t _SizeInWords,const time_t *_Time) __MINGW_ASM_CALL(_wctime32_s); |
| 222 |
#endif |
| 223 |
#endif |
| 224 |
|
| 225 |
#define _WTIME_DEFINED |
| 226 |
#endif |
| 227 |
|
| 228 |
#ifndef RC_INVOKED |
| 229 |
|
| 230 |
/* |
| 231 |
* To prevent ABI issues, the mingw-w64 runtime should not call these |
| 232 |
* functions. Instead it should call the fixed-size variants. |
| 233 |
*/ |
| 234 |
#ifndef _CRTBLD |
| 235 |
#ifdef _USE_32BIT_TIME_T |
| 236 |
time_t __CRTDECL time(time_t *_Time) __MINGW_ASM_CALL(_time32); |
| 237 |
#ifdef _UCRT |
| 238 |
int __CRTDECL timespec_get(struct timespec* _Ts, int _Base) __MINGW_ASM_CALL(_timespec32_get); |
| 239 |
#endif |
| 240 |
double __CRTDECL difftime(time_t _Time1,time_t _Time2) __MINGW_ASM_CALL(_difftime32); |
| 241 |
struct tm *__CRTDECL localtime(const time_t *_Time) __MINGW_ASM_CALL(_localtime32); |
| 242 |
errno_t __CRTDECL localtime_s(struct tm *_Tm,const time_t *_Time) __MINGW_ASM_CALL(_localtime32_s); |
| 243 |
struct tm *__CRTDECL gmtime(const time_t *_Time) __MINGW_ASM_CALL(_gmtime32); |
| 244 |
errno_t __CRTDECL gmtime_s(struct tm *_Tm, const time_t *_Time) __MINGW_ASM_CALL(_gmtime32_s); |
| 245 |
char *__CRTDECL ctime(const time_t *_Time) __MINGW_ASM_CALL(_ctime32); |
| 246 |
errno_t __CRTDECL ctime_s(char *_Buf,size_t _SizeInBytes,const time_t *_Time) __MINGW_ASM_CALL(_ctime32_s); |
| 247 |
time_t __CRTDECL mktime(struct tm *_Tm) __MINGW_ASM_CALL(_mktime32); |
| 248 |
time_t __CRTDECL _mkgmtime(struct tm *_Tm) __MINGW_ASM_CALL(_mkgmtime32); |
| 249 |
#else |
| 250 |
time_t __CRTDECL time(time_t *_Time) __MINGW_ASM_CALL(_time64); |
| 251 |
#ifdef _UCRT |
| 252 |
int __CRTDECL timespec_get(struct timespec* _Ts, int _Base) __MINGW_ASM_CALL(_timespec64_get); |
| 253 |
#endif |
| 254 |
double __CRTDECL difftime(time_t _Time1,time_t _Time2) __MINGW_ASM_CALL(_difftime64); |
| 255 |
struct tm *__CRTDECL localtime(const time_t *_Time) __MINGW_ASM_CALL(_localtime64); |
| 256 |
errno_t __CRTDECL localtime_s(struct tm *_Tm,const time_t *_Time) __MINGW_ASM_CALL(_localtime64_s); |
| 257 |
struct tm *__CRTDECL gmtime(const time_t *_Time) __MINGW_ASM_CALL(_gmtime64); |
| 258 |
errno_t __CRTDECL gmtime_s(struct tm *_Tm, const time_t *_Time) __MINGW_ASM_CALL(_gmtime64_s); |
| 259 |
char *__CRTDECL ctime(const time_t *_Time) __MINGW_ASM_CALL(_ctime64); |
| 260 |
errno_t __CRTDECL ctime_s(char *_Buf,size_t _SizeInBytes,const time_t *_Time) __MINGW_ASM_CALL(_ctime64_s); |
| 261 |
time_t __CRTDECL mktime(struct tm *_Tm) __MINGW_ASM_CALL(_mktime64); |
| 262 |
time_t __CRTDECL _mkgmtime(struct tm *_Tm) __MINGW_ASM_CALL(_mkgmtime64); |
| 263 |
#endif |
| 264 |
#endif /* _CRTBLD */ |
| 265 |
|
| 266 |
#endif /* !RC_INVOKED */ |
| 267 |
|
| 268 |
#if !defined(NO_OLDNAMES) || defined(_POSIX) |
| 269 |
#define CLK_TCK CLOCKS_PER_SEC |
| 270 |
|
| 271 |
#ifdef _UCRT |
| 272 |
#define __MINGW_ATTRIB_DEPRECATED_UCRT \ |
| 273 |
__MINGW_ATTRIB_DEPRECATED_MSG( \ |
| 274 |
"Only provided for source compatibility; this variable might " \ |
| 275 |
"not always be accurate when linking to UCRT.") |
| 276 |
#else |
| 277 |
#define __MINGW_ATTRIB_DEPRECATED_UCRT |
| 278 |
#endif |
| 279 |
|
| 280 |
_CRTIMP extern int daylight __MINGW_ATTRIB_DEPRECATED_UCRT; |
| 281 |
_CRTIMP extern long timezone __MINGW_ATTRIB_DEPRECATED_UCRT; |
| 282 |
_CRTIMP extern char *tzname[2] __MINGW_ATTRIB_DEPRECATED_UCRT; |
| 283 |
void __cdecl tzset(void) __MINGW_ATTRIB_DEPRECATED_MSVC2005; |
| 284 |
#endif |
| 285 |
|
| 286 |
#include <_timeval.h> |
| 287 |
|
| 288 |
#ifndef _TIMEZONE_DEFINED /* also in sys/time.h */ |
| 289 |
#define _TIMEZONE_DEFINED |
| 290 |
struct timezone { |
| 291 |
int tz_minuteswest; |
| 292 |
int tz_dsttime; |
| 293 |
}; |
| 294 |
|
| 295 |
extern int __cdecl mingw_gettimeofday (struct timeval *p, struct timezone *z); |
| 296 |
#endif /* _TIMEZONE_DEFINED */ |
| 297 |
|
| 298 |
#pragma pack(pop) |
| 299 |
|
| 300 |
#if defined(_POSIX_C_SOURCE) && !defined(_POSIX_THREAD_SAFE_FUNCTIONS) |
| 301 |
#define _POSIX_THREAD_SAFE_FUNCTIONS 200112L |
| 302 |
#endif |
| 303 |
|
| 304 |
#ifdef _POSIX_THREAD_SAFE_FUNCTIONS |
| 305 |
__forceinline struct tm *__CRTDECL localtime_r(const time_t *_Time, struct tm *_Tm) { |
| 306 |
return localtime_s(_Tm, _Time) ? NULL : _Tm; |
| 307 |
} |
| 308 |
__forceinline struct tm *__CRTDECL gmtime_r(const time_t *_Time, struct tm *_Tm) { |
| 309 |
return gmtime_s(_Tm, _Time) ? NULL : _Tm; |
| 310 |
} |
| 311 |
__forceinline char *__CRTDECL ctime_r(const time_t *_Time, char *_Str) { |
| 312 |
return ctime_s(_Str, 0x7fffffff, _Time) ? NULL : _Str; |
| 313 |
} |
| 314 |
__forceinline char *__CRTDECL asctime_r(const struct tm *_Tm, char * _Str) { |
| 315 |
return asctime_s(_Str, 0x7fffffff, _Tm) ? NULL : _Str; |
| 316 |
} |
| 317 |
#endif |
| 318 |
|
| 319 |
#ifdef __cplusplus |
| 320 |
} |
| 321 |
#endif |
| 322 |
|
| 323 |
/* POSIX 2008 says clock_gettime and timespec are defined in time.h header, |
| 324 |
but other systems - like Linux, Solaris, etc - tend to declare such |
| 325 |
recent extensions only if the following guards are met. */ |
| 326 |
#if !defined(IN_WINPTHREAD) && \ |
| 327 |
((!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \ |
| 328 |
(_POSIX_C_SOURCE > 2) || defined(__EXTENSIONS__)) |
| 329 |
#include <pthread_time.h> |
| 330 |
#endif |
| 331 |
|
| 332 |
#endif /* End _TIME_H_ */ |
| 333 |
|