zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

time.h (11996B) - Raw


      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 #ifdef _USE_32BIT_TIME_T
    231 time_t __CRTDECL time(time_t *_Time) __MINGW_ASM_CALL(_time32);
    232 #ifdef _UCRT
    233 int __CRTDECL timespec_get(struct timespec* _Ts, int _Base) __MINGW_ASM_CALL(_timespec32_get);
    234 #endif
    235 double __CRTDECL difftime(time_t _Time1,time_t _Time2) __MINGW_ASM_CALL(_difftime32);
    236 struct tm *__CRTDECL localtime(const time_t *_Time) __MINGW_ASM_CALL(_localtime32);
    237 errno_t __CRTDECL localtime_s(struct tm *_Tm,const time_t *_Time) __MINGW_ASM_CALL(_localtime32_s);
    238 struct tm *__CRTDECL gmtime(const time_t *_Time) __MINGW_ASM_CALL(_gmtime32);
    239 errno_t __CRTDECL gmtime_s(struct tm *_Tm, const time_t *_Time) __MINGW_ASM_CALL(_gmtime32_s);
    240 char *__CRTDECL ctime(const time_t *_Time) __MINGW_ASM_CALL(_ctime32);
    241 errno_t __CRTDECL ctime_s(char *_Buf,size_t _SizeInBytes,const time_t *_Time) __MINGW_ASM_CALL(_ctime32_s);
    242 time_t __CRTDECL mktime(struct tm *_Tm) __MINGW_ASM_CALL(_mktime32);
    243 time_t __CRTDECL _mkgmtime(struct tm *_Tm) __MINGW_ASM_CALL(_mkgmtime32);
    244 #else
    245 time_t __CRTDECL time(time_t *_Time) __MINGW_ASM_CALL(_time64);
    246 #ifdef _UCRT
    247 int __CRTDECL timespec_get(struct timespec* _Ts, int _Base) __MINGW_ASM_CALL(_timespec64_get);
    248 #endif
    249 double __CRTDECL difftime(time_t _Time1,time_t _Time2) __MINGW_ASM_CALL(_difftime64);
    250 struct tm *__CRTDECL localtime(const time_t *_Time) __MINGW_ASM_CALL(_localtime64);
    251 errno_t __CRTDECL localtime_s(struct tm *_Tm,const time_t *_Time) __MINGW_ASM_CALL(_localtime64_s);
    252 struct tm *__CRTDECL gmtime(const time_t *_Time) __MINGW_ASM_CALL(_gmtime64);
    253 errno_t __CRTDECL gmtime_s(struct tm *_Tm, const time_t *_Time) __MINGW_ASM_CALL(_gmtime64_s);
    254 char *__CRTDECL ctime(const time_t *_Time) __MINGW_ASM_CALL(_ctime64);
    255 errno_t __CRTDECL ctime_s(char *_Buf,size_t _SizeInBytes,const time_t *_Time) __MINGW_ASM_CALL(_ctime64_s);
    256 time_t __CRTDECL mktime(struct tm *_Tm) __MINGW_ASM_CALL(_mktime64);
    257 time_t __CRTDECL _mkgmtime(struct tm *_Tm) __MINGW_ASM_CALL(_mkgmtime64);
    258 #endif
    259 
    260 #endif /* !RC_INVOKED */
    261 
    262 #if !defined(NO_OLDNAMES) || defined(_POSIX)
    263 #define CLK_TCK CLOCKS_PER_SEC
    264 
    265 #ifdef _UCRT
    266 #define __MINGW_ATTRIB_DEPRECATED_UCRT \
    267     __MINGW_ATTRIB_DEPRECATED_MSG( \
    268         "Only provided for source compatibility; this variable might " \
    269         "not always be accurate when linking to UCRT.")
    270 #else
    271 #define __MINGW_ATTRIB_DEPRECATED_UCRT
    272 #endif
    273 
    274   _CRTIMP extern int daylight __MINGW_ATTRIB_DEPRECATED_UCRT;
    275   _CRTIMP extern long timezone __MINGW_ATTRIB_DEPRECATED_UCRT;
    276   _CRTIMP extern char *tzname[2] __MINGW_ATTRIB_DEPRECATED_UCRT;
    277   void __cdecl tzset(void) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    278 #endif
    279 
    280 #include <_timeval.h>
    281 
    282 #ifndef _TIMEZONE_DEFINED /* also in sys/time.h */
    283 #define _TIMEZONE_DEFINED
    284 struct timezone {
    285   int tz_minuteswest;
    286   int tz_dsttime;
    287 };
    288 
    289   extern int __cdecl mingw_gettimeofday (struct timeval *p, struct timezone *z);
    290 #endif /* _TIMEZONE_DEFINED */
    291 
    292 #pragma pack(pop)
    293 
    294 #if defined(_POSIX_C_SOURCE) && !defined(_POSIX_THREAD_SAFE_FUNCTIONS)
    295 #define _POSIX_THREAD_SAFE_FUNCTIONS 200112L
    296 #endif
    297 
    298 #ifdef _POSIX_THREAD_SAFE_FUNCTIONS
    299 __forceinline struct tm *__CRTDECL localtime_r(const time_t *_Time, struct tm *_Tm) {
    300   return localtime_s(_Tm, _Time) ? NULL : _Tm;
    301 }
    302 __forceinline struct tm *__CRTDECL gmtime_r(const time_t *_Time, struct tm *_Tm) {
    303   return gmtime_s(_Tm, _Time) ? NULL : _Tm;
    304 }
    305 __forceinline char *__CRTDECL ctime_r(const time_t *_Time, char *_Str) {
    306   return ctime_s(_Str, 0x7fffffff, _Time) ? NULL : _Str;
    307 }
    308 __forceinline char *__CRTDECL asctime_r(const struct tm *_Tm, char * _Str) {
    309   return asctime_s(_Str, 0x7fffffff, _Tm) ? NULL : _Str;
    310 }
    311 #endif
    312 
    313 #ifdef __cplusplus
    314 }
    315 #endif
    316 
    317 /* POSIX 2008 says clock_gettime and timespec are defined in time.h header,
    318    but other systems - like Linux, Solaris, etc - tend to declare such
    319    recent extensions only if the following guards are met.  */
    320 #if !defined(IN_WINPTHREAD) && \
    321 	((!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
    322 	 (_POSIX_C_SOURCE > 2) || defined(__EXTENSIONS__))
    323 #include <pthread_time.h>
    324 #endif
    325 
    326 #endif /* End _TIME_H_ */
    327