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 #pragma pack(push,_CRT_PACKING) 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 #ifndef _CRTIMP 22 #define _CRTIMP __declspec(dllimport) 23 #endif 24 25 #ifndef _WCHAR_T_DEFINED 26 #define _WCHAR_T_DEFINED 27 typedef unsigned short wchar_t; 28 #endif 29 30 #ifndef _TIME32_T_DEFINED 31 #define _TIME32_T_DEFINED 32 typedef long __time32_t; 33 #endif 34 35 #ifndef _TIME64_T_DEFINED 36 #define _TIME64_T_DEFINED 37 __MINGW_EXTENSION typedef __int64 __time64_t; 38 #endif 39 40 #ifndef _TIME_T_DEFINED 41 #define _TIME_T_DEFINED 42 #ifdef _USE_32BIT_TIME_T 43 typedef __time32_t time_t; 44 #else 45 typedef __time64_t time_t; 46 #endif 47 #endif 48 49 #ifndef _CLOCK_T_DEFINED 50 #define _CLOCK_T_DEFINED 51 typedef long clock_t; 52 #endif 53 54 #ifndef _SIZE_T_DEFINED 55 #define _SIZE_T_DEFINED 56 #undef size_t 57 #ifdef _WIN64 58 __MINGW_EXTENSION typedef unsigned __int64 size_t; 59 #else 60 typedef unsigned int size_t; 61 #endif 62 #endif 63 64 #ifndef _SSIZE_T_DEFINED 65 #define _SSIZE_T_DEFINED 66 #undef ssize_t 67 #ifdef _WIN64 68 __MINGW_EXTENSION typedef __int64 ssize_t; 69 #else 70 typedef int ssize_t; 71 #endif 72 #endif 73 74 #ifndef NULL 75 #ifdef __cplusplus 76 #ifndef _WIN64 77 #define NULL 0 78 #else 79 #define NULL 0LL 80 #endif /* W64 */ 81 #else 82 #define NULL ((void *)0) 83 #endif 84 #endif 85 86 #ifndef _TM_DEFINED 87 #define _TM_DEFINED 88 struct tm { 89 int tm_sec; 90 int tm_min; 91 int tm_hour; 92 int tm_mday; 93 int tm_mon; 94 int tm_year; 95 int tm_wday; 96 int tm_yday; 97 int tm_isdst; 98 }; 99 #endif 100 101 #define CLOCKS_PER_SEC 1000 102 103 __MINGW_IMPORT int _daylight; 104 __MINGW_IMPORT long _dstbias; 105 __MINGW_IMPORT long _timezone; 106 __MINGW_IMPORT char * _tzname[2]; 107 108 _CRTIMP errno_t __cdecl _get_daylight(int *_Daylight); 109 _CRTIMP errno_t __cdecl _get_dstbias(long *_Daylight_savings_bias); 110 _CRTIMP errno_t __cdecl _get_timezone(long *_Timezone); 111 _CRTIMP errno_t __cdecl _get_tzname(size_t *_ReturnValue,char *_Buffer,size_t _SizeInBytes,int _Index); 112 char *__cdecl asctime(const struct tm *_Tm) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; 113 _CRTIMP errno_t __cdecl asctime_s (char *_Buf,size_t _SizeInWords,const struct tm *_Tm); 114 char *__cdecl _ctime32(const __time32_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; 115 _CRTIMP errno_t __cdecl _ctime32_s (char *_Buf,size_t _SizeInBytes,const __time32_t *_Time); 116 clock_t __cdecl clock(void); 117 double __cdecl _difftime32(__time32_t _Time1,__time32_t _Time2); 118 struct tm *__cdecl _gmtime32(const __time32_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; 119 _CRTIMP errno_t __cdecl _gmtime32_s (struct tm *_Tm,const __time32_t *_Time); 120 struct tm *__cdecl _localtime32(const __time32_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; 121 _CRTIMP errno_t __cdecl _localtime32_s (struct tm *_Tm,const __time32_t *_Time); 122 size_t __cdecl strftime(char * __restrict__ _Buf,size_t _SizeInBytes,const char * __restrict__ _Format,const struct tm * __restrict__ _Tm); 123 _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); 124 _CRTIMP char *__cdecl _strdate(char *_Buffer) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; 125 _CRTIMP errno_t __cdecl _strdate_s (char *_Buf,size_t _SizeInBytes); 126 _CRTIMP char *__cdecl _strtime(char *_Buffer) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; 127 _CRTIMP errno_t __cdecl _strtime_s (char *_Buf ,size_t _SizeInBytes); 128 __time32_t __cdecl _time32(__time32_t *_Time); 129 __time32_t __cdecl _mktime32(struct tm *_Tm); 130 __time32_t __cdecl _mkgmtime32(struct tm *_Tm); 131 132 #if defined (_POSIX_) || defined(__GNUC__) 133 void __cdecl tzset(void) __MINGW_ATTRIB_DEPRECATED_MSVC2005; 134 #endif 135 #if !defined (_POSIX_) 136 _CRTIMP void __cdecl _tzset(void); 137 #endif 138 139 double __cdecl _difftime64(__time64_t _Time1,__time64_t _Time2); 140 _CRTIMP char *__cdecl _ctime64(const __time64_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; 141 errno_t __cdecl _ctime64_s (char *_Buf,size_t _SizeInBytes,const __time64_t *_Time); 142 _CRTIMP struct tm *__cdecl _gmtime64(const __time64_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; 143 _CRTIMP errno_t __cdecl _gmtime64_s (struct tm *_Tm,const __time64_t *_Time); 144 _CRTIMP struct tm *__cdecl _localtime64(const __time64_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; 145 _CRTIMP errno_t __cdecl _localtime64_s (struct tm *_Tm,const __time64_t *_Time); 146 _CRTIMP __time64_t __cdecl _mktime64(struct tm *_Tm); 147 _CRTIMP __time64_t __cdecl _mkgmtime64(struct tm *_Tm); 148 _CRTIMP __time64_t __cdecl _time64(__time64_t *_Time); 149 unsigned __cdecl _getsystime(struct tm *_Tm); 150 unsigned __cdecl _setsystime(struct tm *_Tm,unsigned _MilliSec); 151 152 #ifndef _WTIME_DEFINED 153 _CRTIMP wchar_t *__cdecl _wasctime(const struct tm *_Tm); 154 _CRTIMP errno_t __cdecl _wasctime_s (wchar_t *_Buf,size_t _SizeInWords,const struct tm *_Tm); 155 wchar_t *__cdecl _wctime32(const __time32_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; 156 _CRTIMP errno_t __cdecl _wctime32_s (wchar_t *_Buf,size_t _SizeInWords,const __time32_t *_Time); 157 size_t __cdecl wcsftime(wchar_t * __restrict__ _Buf,size_t _SizeInWords,const wchar_t * __restrict__ _Format,const struct tm * __restrict__ _Tm); 158 _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); 159 _CRTIMP wchar_t *__cdecl _wstrdate(wchar_t *_Buffer) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; 160 _CRTIMP errno_t __cdecl _wstrdate_s (wchar_t *_Buf,size_t _SizeInWords); 161 _CRTIMP wchar_t *__cdecl _wstrtime(wchar_t *_Buffer) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; 162 _CRTIMP errno_t __cdecl _wstrtime_s (wchar_t *_Buf,size_t _SizeInWords); 163 _CRTIMP wchar_t *__cdecl _wctime64(const __time64_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; 164 _CRTIMP errno_t __cdecl _wctime64_s (wchar_t *_Buf,size_t _SizeInWords,const __time64_t *_Time); 165 166 #if !defined (RC_INVOKED) && !defined (_INC_WTIME_INL) 167 #define _INC_WTIME_INL 168 wchar_t *__cdecl _wctime(const time_t *) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; 169 #ifndef __CRT__NO_INLINE 170 #ifndef _USE_32BIT_TIME_T 171 __CRT_INLINE wchar_t *__cdecl _wctime(const time_t *_Time) { return _wctime64(_Time); } 172 #else 173 __CRT_INLINE wchar_t *__cdecl _wctime(const time_t *_Time) { return _wctime32(_Time); } 174 #endif 175 #endif /* __CRT__NO_INLINE */ 176 #endif 177 178 #if !defined (RC_INVOKED) && !defined (_INC_WTIME_S_INL) 179 #define _INC_WTIME_S_INL 180 errno_t __cdecl _wctime_s(wchar_t *, size_t, const time_t *); 181 #ifndef __CRT__NO_INLINE 182 #ifndef _USE_32BIT_TIME_T 183 __CRT_INLINE errno_t __cdecl _wctime_s (wchar_t *_Buffer,size_t _SizeInWords,const time_t *_Time) { return _wctime64_s (_Buffer,_SizeInWords,_Time); } 184 #else 185 __CRT_INLINE errno_t __cdecl _wctime_s (wchar_t *_Buffer,size_t _SizeInWords,const time_t *_Time) { return _wctime32_s (_Buffer,_SizeInWords,_Time); } 186 #endif 187 #endif /* __CRT__NO_INLINE */ 188 #endif 189 190 #define _WTIME_DEFINED 191 #endif 192 193 #ifndef RC_INVOKED 194 double __cdecl difftime(time_t _Time1,time_t _Time2); 195 char *__cdecl ctime(const time_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; 196 struct tm *__cdecl gmtime(const time_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; 197 struct tm *__cdecl localtime(const time_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; 198 199 time_t __cdecl mktime(struct tm *_Tm); 200 time_t __cdecl _mkgmtime(struct tm *_Tm); 201 time_t __cdecl time(time_t *_Time); 202 203 #ifndef __CRT__NO_INLINE 204 #if !defined(_USE_32BIT_TIME_T) 205 __CRT_INLINE double __cdecl difftime(time_t _Time1,time_t _Time2) 206 { return _difftime64(_Time1,_Time2); } 207 __CRT_INLINE char *__cdecl ctime(const time_t *_Time) { return _ctime64(_Time); } 208 __CRT_INLINE struct tm *__cdecl gmtime(const time_t *_Time) { return _gmtime64(_Time); } 209 __CRT_INLINE struct tm *__cdecl localtime(const time_t *_Time) { return _localtime64(_Time); } 210 __CRT_INLINE time_t __cdecl mktime(struct tm *_Tm) { return _mktime64(_Tm); } 211 __CRT_INLINE time_t __cdecl _mkgmtime(struct tm *_Tm) { return _mkgmtime64(_Tm); } 212 __CRT_INLINE time_t __cdecl time(time_t *_Time) { return _time64(_Time); } 213 #else 214 __CRT_INLINE double __cdecl difftime(time_t _Time1,time_t _Time2) 215 { return _difftime32(_Time1,_Time2); } 216 __CRT_INLINE char *__cdecl ctime(const time_t *_Time) { return _ctime32(_Time); } 217 __CRT_INLINE struct tm *__cdecl localtime(const time_t *_Time) { return _localtime32(_Time); } 218 __CRT_INLINE time_t __cdecl mktime(struct tm *_Tm) { return _mktime32(_Tm); } 219 __CRT_INLINE struct tm *__cdecl gmtime(const time_t *_Time) { return _gmtime32(_Time); } 220 __CRT_INLINE time_t __cdecl _mkgmtime(struct tm *_Tm) { return _mkgmtime32(_Tm); } 221 __CRT_INLINE time_t __cdecl time(time_t *_Time) { return _time32(_Time); } 222 #endif /* !_USE_32BIT_TIME_T */ 223 #endif /* !__CRT__NO_INLINE */ 224 225 #ifdef _USE_32BIT_TIME_T 226 __forceinline errno_t __cdecl localtime_s(struct tm *_Tm,const time_t *_Time) { return _localtime32_s(_Tm,_Time); } 227 __forceinline errno_t __cdecl gmtime_s(struct tm *_Tm, const time_t *_Time) { return _gmtime32_s(_Tm, _Time); } 228 __forceinline errno_t __cdecl ctime_s(char *_Buf,size_t _SizeInBytes,const time_t *_Time) { return _ctime32_s(_Buf,_SizeInBytes,_Time); } 229 230 #else 231 __forceinline errno_t __cdecl localtime_s(struct tm *_Tm,const time_t *_Time) { return _localtime64_s(_Tm,_Time); } 232 __forceinline errno_t __cdecl gmtime_s(struct tm *_Tm, const time_t *_Time) { return _gmtime64_s(_Tm, _Time); } 233 __forceinline errno_t __cdecl ctime_s(char *_Buf,size_t _SizeInBytes,const time_t *_Time) { return _ctime64_s(_Buf,_SizeInBytes,_Time); } 234 #endif 235 #endif /* !RC_INVOKED */ 236 237 #if !defined(NO_OLDNAMES) || defined(_POSIX) 238 #define CLK_TCK CLOCKS_PER_SEC 239 240 _CRTIMP extern int daylight; 241 _CRTIMP extern long timezone; 242 _CRTIMP extern char *tzname[2]; 243 void __cdecl tzset(void) __MINGW_ATTRIB_DEPRECATED_MSVC2005; 244 #endif 245 246 #include <_timeval.h> 247 248 #ifndef _TIMEZONE_DEFINED /* also in sys/time.h */ 249 #define _TIMEZONE_DEFINED 250 struct timezone { 251 int tz_minuteswest; 252 int tz_dsttime; 253 }; 254 255 extern int __cdecl mingw_gettimeofday (struct timeval *p, struct timezone *z); 256 #endif /* _TIMEZONE_DEFINED */ 257 258 #ifdef __cplusplus 259 } 260 #endif 261 262 #pragma pack(pop) 263 264 #if defined(_POSIX_C_SOURCE) && !defined(_POSIX_THREAD_SAFE_FUNCTIONS) 265 #define _POSIX_THREAD_SAFE_FUNCTIONS 200112L 266 #endif 267 268 #ifdef _POSIX_THREAD_SAFE_FUNCTIONS 269 __forceinline struct tm *__cdecl localtime_r(const time_t *_Time, struct tm *_Tm) { 270 return localtime_s(_Tm, _Time) ? NULL : _Tm; 271 } 272 __forceinline struct tm *__cdecl gmtime_r(const time_t *_Time, struct tm *_Tm) { 273 return gmtime_s(_Tm, _Time) ? NULL : _Tm; 274 } 275 __forceinline char *__cdecl ctime_r(const time_t *_Time, char *_Str) { 276 return ctime_s(_Str, 0x7fffffff, _Time) ? NULL : _Str; 277 } 278 __forceinline char *__cdecl asctime_r(const struct tm *_Tm, char * _Str) { 279 return asctime_s(_Str, 0x7fffffff, _Tm) ? NULL : _Str; 280 } 281 #endif 282 283 /* Adding timespec definition. */ 284 #include <sys/timeb.h> 285 286 /* POSIX 2008 says clock_gettime and timespec are defined in time.h header, 287 but other systems - like Linux, Solaris, etc - tend to declare such 288 recent extensions only if the following guards are met. */ 289 #if !defined(IN_WINPTHREAD) && \ 290 ((!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \ 291 (_POSIX_C_SOURCE > 2) || defined(__EXTENSIONS__)) 292 #include <pthread_time.h> 293 #endif 294 295 #endif /* End _TIME_H_ */ 296 297