Home | History | Annotate | Download | only in include
      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   char *__cdecl _ctime32(const __time32_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
    114   clock_t __cdecl clock(void);
    115   double __cdecl _difftime32(__time32_t _Time1,__time32_t _Time2);
    116   struct tm *__cdecl _gmtime32(const __time32_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
    117   struct tm *__cdecl _localtime32(const __time32_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
    118   size_t __cdecl strftime(char * __restrict__ _Buf,size_t _SizeInBytes,const char * __restrict__ _Format,const struct tm * __restrict__ _Tm);
    119   _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);
    120   _CRTIMP char *__cdecl _strdate(char *_Buffer) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
    121   _CRTIMP char *__cdecl _strtime(char *_Buffer) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
    122   __time32_t __cdecl _time32(__time32_t *_Time);
    123   __time32_t __cdecl _mktime32(struct tm *_Tm);
    124   __time32_t __cdecl _mkgmtime32(struct tm *_Tm);
    125 #if defined (_POSIX_) || defined(__GNUC__)
    126   void __cdecl tzset(void) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    127 #endif
    128 #if !defined (_POSIX_)
    129   _CRTIMP void __cdecl _tzset(void);
    130 #endif
    131 
    132   double __cdecl _difftime64(__time64_t _Time1,__time64_t _Time2);
    133   _CRTIMP char *__cdecl _ctime64(const __time64_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
    134   _CRTIMP struct tm *__cdecl _gmtime64(const __time64_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
    135   _CRTIMP struct tm *__cdecl _localtime64(const __time64_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
    136   _CRTIMP __time64_t __cdecl _mktime64(struct tm *_Tm);
    137   _CRTIMP __time64_t __cdecl _mkgmtime64(struct tm *_Tm);
    138   _CRTIMP __time64_t __cdecl _time64(__time64_t *_Time);
    139   unsigned __cdecl _getsystime(struct tm *_Tm);
    140   unsigned __cdecl _setsystime(struct tm *_Tm,unsigned _MilliSec);
    141 
    142 #ifndef _WTIME_DEFINED
    143   _CRTIMP wchar_t *__cdecl _wasctime(const struct tm *_Tm);
    144   wchar_t *__cdecl _wctime32(const __time32_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
    145   size_t __cdecl wcsftime(wchar_t * __restrict__ _Buf,size_t _SizeInWords,const wchar_t * __restrict__ _Format,const struct tm * __restrict__ _Tm);
    146   _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);
    147   _CRTIMP wchar_t *__cdecl _wstrdate(wchar_t *_Buffer) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
    148   _CRTIMP wchar_t *__cdecl _wstrtime(wchar_t *_Buffer) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
    149   _CRTIMP wchar_t *__cdecl _wctime64(const __time64_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
    150 
    151 #if !defined (RC_INVOKED) && !defined (_INC_WTIME_INL)
    152 #define _INC_WTIME_INL
    153   wchar_t *__cdecl _wctime(const time_t *) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
    154 #ifndef __CRT__NO_INLINE
    155 #ifndef _USE_32BIT_TIME_T
    156   __CRT_INLINE wchar_t *__cdecl _wctime(const time_t *_Time) { return _wctime64(_Time); }
    157 #else
    158   __CRT_INLINE wchar_t *__cdecl _wctime(const time_t *_Time) { return _wctime32(_Time); }
    159 #endif
    160 #endif /* __CRT__NO_INLINE */
    161 #endif
    162 
    163 #define _WTIME_DEFINED
    164 #endif
    165 
    166 #ifndef RC_INVOKED
    167 double __cdecl difftime(time_t _Time1,time_t _Time2);
    168 char *__cdecl ctime(const time_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
    169 struct tm *__cdecl gmtime(const time_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
    170 struct tm *__cdecl localtime(const time_t *_Time) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
    171 
    172 #ifdef _POSIX
    173 #ifdef __GNUC__ /* FIXME: Other compilers that these macros work with? */
    174 #ifndef localtime_r
    175 #define localtime_r(_Time, _Tm)	({ struct tm *___tmp_tm =		\
    176 						localtime((_Time));	\
    177 						if (___tmp_tm) {	\
    178 						  *(_Tm) = *___tmp_tm;	\
    179 						  ___tmp_tm = (_Tm);	\
    180 						}			\
    181 						___tmp_tm;	})
    182 #endif
    183 #ifndef gmtime_r
    184 #define gmtime_r(_Time,_Tm)	({ struct tm *___tmp_tm =		\
    185 						gmtime((_Time));	\
    186 						if (___tmp_tm) {	\
    187 						  *(_Tm) = *___tmp_tm;	\
    188 						  ___tmp_tm = (_Tm);	\
    189 						}			\
    190 						___tmp_tm;	})
    191 #endif
    192 #ifndef ctime_r
    193 #define ctime_r(_Time,_Str)	({ char *___tmp_tm = ctime((_Time));	\
    194 						if (___tmp_tm)		\
    195 						 ___tmp_tm =		\
    196 						   strcpy((_Str),___tmp_tm); \
    197 						___tmp_tm;	})
    198 #endif
    199 #ifndef asctime_r
    200 #define asctime_r(_Tm, _Buf)	({ char *___tmp_tm = asctime((_Tm));	\
    201 						if (___tmp_tm)		\
    202 						 ___tmp_tm =		\
    203 						   strcpy((_Buf),___tmp_tm);\
    204 						___tmp_tm;	})
    205 #endif
    206 #else /* NOT GCC: */
    207       /* FIXME: These are more generic but call the main function twice! */
    208 #ifndef localtime_r
    209 #define localtime_r(_Time, _Tm) (localtime ((_Time)) ? *(_Tm) = *localtime ((_Time),(_Tm)) : 0)
    210 #endif
    211 #ifndef gmtime_r
    212 #define gmtime_r(_Time,_Tm) (gmtime ((_Time)) ? (*(_Tm) = *gmtime (_Time),(_Tm)) : 0)
    213 #endif
    214 #ifndef ctime_r
    215 #define ctime_r(_Time,_Str) (ctime ((_Time)) ? (strcpy((_Str),ctime ((_Time))),(_Str)) : 0)
    216 #endif
    217 #endif /* __GNUC__ */
    218 #endif /* _POSIX */
    219 
    220 time_t __cdecl mktime(struct tm *_Tm);
    221 time_t __cdecl _mkgmtime(struct tm *_Tm);
    222 time_t __cdecl time(time_t *_Time);
    223 
    224 #ifndef __CRT__NO_INLINE
    225 #if !defined(_USE_32BIT_TIME_T)
    226 __CRT_INLINE double __cdecl difftime(time_t _Time1,time_t _Time2)
    227   { return _difftime64(_Time1,_Time2); }
    228 __CRT_INLINE char *__cdecl ctime(const time_t *_Time) { return _ctime64(_Time); }
    229 __CRT_INLINE struct tm *__cdecl gmtime(const time_t *_Time) { return _gmtime64(_Time); }
    230 __CRT_INLINE struct tm *__cdecl localtime(const time_t *_Time) { return _localtime64(_Time); }
    231 __CRT_INLINE time_t __cdecl mktime(struct tm *_Tm) { return _mktime64(_Tm); }
    232 __CRT_INLINE time_t __cdecl _mkgmtime(struct tm *_Tm) { return _mkgmtime64(_Tm); }
    233 __CRT_INLINE time_t __cdecl time(time_t *_Time) { return _time64(_Time); }
    234 #else
    235 __CRT_INLINE double __cdecl difftime(time_t _Time1,time_t _Time2)
    236   { return _difftime32(_Time1,_Time2); }
    237 __CRT_INLINE char *__cdecl ctime(const time_t *_Time) { return _ctime32(_Time); }
    238 __CRT_INLINE struct tm *__cdecl localtime(const time_t *_Time) { return _localtime32(_Time); }
    239 __CRT_INLINE time_t __cdecl mktime(struct tm *_Tm) { return _mktime32(_Tm); }
    240 __CRT_INLINE struct tm *__cdecl gmtime(const time_t *_Time) { return _gmtime32(_Time); }
    241 __CRT_INLINE time_t __cdecl _mkgmtime(struct tm *_Tm) { return _mkgmtime32(_Tm); }
    242 __CRT_INLINE time_t __cdecl time(time_t *_Time) { return _time32(_Time); }
    243 #endif /* !_USE_32BIT_TIME_T */
    244 #endif /* !__CRT__NO_INLINE */
    245 #endif /* !RC_INVOKED */
    246 
    247 #if !defined(NO_OLDNAMES) || defined(_POSIX)
    248 #define CLK_TCK CLOCKS_PER_SEC
    249 
    250   _CRTIMP extern int daylight;
    251   _CRTIMP extern long timezone;
    252   _CRTIMP extern char *tzname[2];
    253   void __cdecl tzset(void) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
    254 #endif
    255 
    256 #include <_timeval.h>
    257 
    258 #ifndef _TIMEZONE_DEFINED /* also in sys/time.h */
    259 #define _TIMEZONE_DEFINED
    260 struct timezone {
    261   int tz_minuteswest;
    262   int tz_dsttime;
    263 };
    264 
    265   extern int __cdecl mingw_gettimeofday (struct timeval *p, struct timezone *z);
    266 #endif /* _TIMEZONE_DEFINED */
    267 
    268 #ifdef __cplusplus
    269 }
    270 #endif
    271 
    272 #pragma pack(pop)
    273 
    274 #include <sec_api/time_s.h>
    275 
    276 /* Adding timespec definition.  */
    277 #include <sys/timeb.h>
    278 
    279 /* POSIX 2008 says clock_gettime and timespec are defined in time.h header,
    280    but other systems - like Linux, Solaris, etc - tend to declare such
    281    recent extensions only if the following guards are met.  */
    282 #if !defined(IN_WINPTHREAD) && \
    283 	((!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
    284 	 (_POSIX_C_SOURCE > 2) || defined(__EXTENSIONS__))
    285 #include <pthread_time.h>
    286 #endif
    287 
    288 #endif /* End _TIME_H_ */
    289 
    290