OSDN Git Service

Refactor to avoid possible time_t conflicts across headers.
[mingw/mingw-org-wsl.git] / mingwrt / include / time.h
1 /*
2  * time.h
3  *
4  * Type definitions and function declarations relating to date and time.
5  *
6  * $Id$
7  *
8  * Written by Rob Savoye <rob@cygnus.com>
9  * Copyright (C) 1997-2007, 2011, 2015, MinGW.org Project.
10  *
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a
13  * copy of this software and associated documentation files (the "Software"),
14  * to deal in the Software without restriction, including without limitation
15  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16  * and/or sell copies of the Software, and to permit persons to whom the
17  * Software is furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice, this permission notice, and the following
20  * disclaimer shall be included in all copies or substantial portions of
21  * the Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
26  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER
29  * DEALINGS IN THE SOFTWARE.
30  *
31  */
32 #ifndef _TIME_H
33 #define _TIME_H
34
35 /* All the headers include this file. */
36 #include <_mingw.h>
37
38 /* Number of clock ticks per second. A clock tick is the unit by which
39  * processor time is measured and is returned by 'clock'.
40  */
41 #define CLOCKS_PER_SEC  ((clock_t)(1000))
42 #define CLK_TCK         CLOCKS_PER_SEC
43
44 #ifndef RC_INVOKED
45 /*
46  * Some elements declared in time.h may also be required by other
47  * header files, without necessarily including time.h itself; such
48  * elements are declared in the local parts/time.h system header file.
49  * Declarations for such elements must be selected prior to inclusion:
50  */
51 #define __need_time_t
52 #define __need_struct_timespec
53 #include <parts/time.h>
54
55 /* time.h is also required to duplicate the following type definitions,
56  * which are nominally defined in stddef.h
57  */
58 #define __need_NULL
59 #define __need_wchar_t
60 #define __need_size_t
61 #include <stddef.h>
62
63 /* A type for measuring processor time in clock ticks; (no need to
64  * guard this, since it isn't defined elsewhere).
65  */
66 typedef long clock_t;
67
68 #ifndef _TM_DEFINED
69 /*
70  * A structure for storing all kinds of useful information about the
71  * current (or another) time.
72  */
73 struct tm
74 {
75         int     tm_sec;         /* Seconds: 0-59 (K&R says 0-61?) */
76         int     tm_min;         /* Minutes: 0-59 */
77         int     tm_hour;        /* Hours since midnight: 0-23 */
78         int     tm_mday;        /* Day of the month: 1-31 */
79         int     tm_mon;         /* Months *since* january: 0-11 */
80         int     tm_year;        /* Years since 1900 */
81         int     tm_wday;        /* Days since Sunday (0-6) */
82         int     tm_yday;        /* Days since Jan. 1: 0-365 */
83         int     tm_isdst;       /* +1 Daylight Savings Time, 0 No DST,
84                                  * -1 don't know */
85 };
86 #define _TM_DEFINED
87 #endif
88
89 _BEGIN_C_DECLS
90
91 _CRTIMP clock_t __cdecl __MINGW_NOTHROW clock (void);
92 #if __MSVCRT_VERSION__ < 0x0800
93 _CRTIMP time_t __cdecl __MINGW_NOTHROW  time (time_t*);
94 _CRTIMP double __cdecl __MINGW_NOTHROW  difftime (time_t, time_t);
95 _CRTIMP time_t __cdecl __MINGW_NOTHROW  mktime (struct tm*);
96 #endif
97
98 /*
99  * These functions write to and return pointers to static buffers that may
100  * be overwritten by other function calls. Yikes!
101  *
102  * NOTE: localtime, and perhaps the others of the four functions grouped
103  * below may return NULL if their argument is not 'acceptable'. Also note
104  * that calling asctime with a NULL pointer will produce an Invalid Page
105  * Fault and crap out your program. Guess how I know. Hint: stat called on
106  * a directory gives 'invalid' times in st_atime etc...
107  */
108 _CRTIMP char* __cdecl __MINGW_NOTHROW           asctime (const struct tm*);
109 #if __MSVCRT_VERSION__ < 0x0800
110 _CRTIMP char* __cdecl __MINGW_NOTHROW           ctime (const time_t*);
111 _CRTIMP struct tm*  __cdecl __MINGW_NOTHROW     gmtime (const time_t*);
112 _CRTIMP struct tm*  __cdecl __MINGW_NOTHROW     localtime (const time_t*);
113 #endif
114
115 _CRTIMP size_t __cdecl __MINGW_NOTHROW          strftime (char*, size_t, const char*, const struct tm*);
116
117 #ifndef __STRICT_ANSI__
118
119 extern _CRTIMP void __cdecl __MINGW_NOTHROW     _tzset (void);
120
121 #ifndef _NO_OLDNAMES
122 extern _CRTIMP void __cdecl __MINGW_NOTHROW     tzset (void);
123 #endif
124
125 _CRTIMP char* __cdecl __MINGW_NOTHROW   _strdate(char*);
126 _CRTIMP char* __cdecl __MINGW_NOTHROW   _strtime(char*);
127
128 /* These require newer versions of msvcrt.dll (6.10 or higher). */
129 #if __MSVCRT_VERSION__ >= 0x0601
130 _CRTIMP __time64_t __cdecl __MINGW_NOTHROW  _time64( __time64_t*);
131 _CRTIMP __time64_t __cdecl __MINGW_NOTHROW  _mktime64 (struct tm*);
132 _CRTIMP char* __cdecl __MINGW_NOTHROW _ctime64 (const __time64_t*);
133 _CRTIMP struct tm*  __cdecl __MINGW_NOTHROW _gmtime64 (const __time64_t*);
134 _CRTIMP struct tm*  __cdecl __MINGW_NOTHROW _localtime64 (const __time64_t*);
135 #endif /* __MSVCRT_VERSION__ >= 0x0601 */
136
137 /* These require newer versions of msvcrt.dll (8.00 or higher). */
138 #if __MSVCRT_VERSION__ >= 0x0800
139 _CRTIMP __time32_t __cdecl __MINGW_NOTHROW      _time32 (__time32_t*);
140 _CRTIMP double     __cdecl __MINGW_NOTHROW      _difftime32 (__time32_t, __time32_t);
141 _CRTIMP double     __cdecl __MINGW_NOTHROW      _difftime64 (__time64_t, __time64_t);
142 _CRTIMP __time32_t __cdecl __MINGW_NOTHROW      _mktime32 (struct tm*);
143 _CRTIMP __time32_t __cdecl __MINGW_NOTHROW      _mkgmtime32 (struct tm*);
144 _CRTIMP __time64_t __cdecl __MINGW_NOTHROW      _mkgmtime64 (struct tm*);
145 _CRTIMP char*      __cdecl __MINGW_NOTHROW      _ctime32 (const __time32_t*);
146 _CRTIMP struct tm* __cdecl __MINGW_NOTHROW      _gmtime32 (const __time32_t*);
147 _CRTIMP struct tm* __cdecl __MINGW_NOTHROW      _localtime32 (const __time32_t*);
148 #ifndef _USE_32BIT_TIME_T
149 _CRTALIAS time_t           __cdecl __MINGW_NOTHROW      time (time_t* _v)                 { return(_time64 (_v)); }
150 _CRTALIAS double           __cdecl __MINGW_NOTHROW      difftime (time_t _v1, time_t _v2) { return(_difftime64 (_v1,_v2)); }
151 _CRTALIAS time_t           __cdecl __MINGW_NOTHROW      mktime (struct tm* _v)            { return(_mktime64 (_v)); }
152 _CRTALIAS time_t           __cdecl __MINGW_NOTHROW      _mkgmtime (struct tm* _v)         { return(_mkgmtime64 (_v)); }
153 _CRTALIAS char*            __cdecl __MINGW_NOTHROW      ctime (const time_t* _v)          { return(_ctime64 (_v)); }
154 _CRTALIAS struct tm*       __cdecl __MINGW_NOTHROW      gmtime (const time_t* _v)         { return(_gmtime64 (_v)); }
155 _CRTALIAS struct tm*       __cdecl __MINGW_NOTHROW      localtime (const time_t* _v)      { return(_localtime64 (_v)); }
156 #else
157 _CRTALIAS time_t           __cdecl __MINGW_NOTHROW      time (time_t* _v)                 { return(_time32 (_v)); }
158 _CRTALIAS double           __cdecl __MINGW_NOTHROW      difftime (time_t _v1, time_t _v2) { return(_difftime32 (_v1,_v2)); }
159 _CRTALIAS time_t           __cdecl __MINGW_NOTHROW      mktime (struct tm* _v)            { return(_mktime32 (_v)); }
160 _CRTALIAS time_t           __cdecl __MINGW_NOTHROW      _mkgmtime (struct tm* _v)         { return(_mkgmtime32 (_v)); }
161 _CRTALIAS char*            __cdecl __MINGW_NOTHROW      ctime (const time_t* _v)          { return(_ctime32 (_v)); }
162 _CRTALIAS struct tm*       __cdecl __MINGW_NOTHROW      gmtime (const time_t* _v)         { return(_gmtime32 (_v)); }
163 _CRTALIAS struct tm*       __cdecl __MINGW_NOTHROW      localtime (const time_t* _v)      { return(_localtime32 (_v)); }
164 #endif /* !_USE_32BIT_TIME_T */
165 #endif /* __MSVCRT_VERSION__ >= 0x0800 */
166
167 /* _daylight: non zero if daylight savings time is used.
168  * _timezone: difference in seconds between GMT and local time.
169  * _tzname: standard/daylight savings time zone names (an array with two
170  *          elements).
171  */
172 #ifdef __MSVCRT__
173
174 /* These are for compatibility with pre-VC 5.0 suppied MSVCRT. */
175 extern _CRTIMP int* __cdecl __MINGW_NOTHROW     __p__daylight (void);
176 extern _CRTIMP long* __cdecl __MINGW_NOTHROW    __p__timezone (void);
177 extern _CRTIMP char** __cdecl __MINGW_NOTHROW   __p__tzname (void);
178
179 __MINGW_IMPORT int      _daylight;
180 __MINGW_IMPORT long     _timezone;
181 __MINGW_IMPORT char     *_tzname[2];
182
183 #else /* not __MSVCRT (ie. crtdll) */
184
185 #ifndef __DECLSPEC_SUPPORTED
186
187 extern int*     _imp___daylight_dll;
188 extern long*    _imp___timezone_dll;
189 extern char**   _imp___tzname;
190
191 #define _daylight       (*_imp___daylight_dll)
192 #define _timezone       (*_imp___timezone_dll)
193 #define _tzname         (*_imp___tzname)
194
195 #else /* __DECLSPEC_SUPPORTED */
196
197 __MINGW_IMPORT int      _daylight_dll;
198 __MINGW_IMPORT long     _timezone_dll;
199 __MINGW_IMPORT char*    _tzname[2];
200
201 #define _daylight       _daylight_dll
202 #define _timezone       _timezone_dll
203
204 #endif /* __DECLSPEC_SUPPORTED */
205 #endif /* ! __MSVCRT__ */
206 #endif /* ! __STRICT_ANSI__ */
207
208 #ifndef _NO_OLDNAMES
209 #ifdef __MSVCRT__
210
211 /* These go in the oldnames import library for MSVCRT.
212  */
213 __MINGW_IMPORT int      daylight;
214 __MINGW_IMPORT long     timezone;
215 __MINGW_IMPORT char     *tzname[2];
216
217 #else /* ! __MSVCRT__ */
218 /*
219  * CRTDLL is royally messed up when it comes to these macros.
220  * TODO: import and alias these via oldnames import library instead
221  * of macros.
222  */
223 #define daylight        _daylight
224 /*
225  * NOTE: timezone not defined as a macro because it would conflict with
226  * struct timezone in sys/time.h.  Also, tzname used to a be macro, but
227  * now it's in moldname.
228  */
229 __MINGW_IMPORT char     *tzname[2];
230
231 #endif /* ! __MSVCRT__ */
232 #endif /* ! _NO_OLDNAMES */
233
234 #ifndef _WTIME_DEFINED
235 /* wide function prototypes, also declared in wchar.h */
236 #ifndef __STRICT_ANSI__
237 #ifdef __MSVCRT__
238 _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW        _wasctime(const struct tm*);
239 #if __MSVCRT_VERSION__ < 0x0800
240 _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW        _wctime(const time_t*);
241 #endif
242 _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW        _wstrdate(wchar_t*);
243 _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW        _wstrtime(wchar_t*);
244 #if __MSVCRT_VERSION__ >= 0x0601
245 _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW        _wctime64 (const __time64_t*);
246 #endif
247 #if __MSVCRT_VERSION__ >= 0x0800
248 _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW        _wctime32 (const __time32_t*);
249 #ifndef _USE_32BIT_TIME_T
250 _CRTALIAS wchar_t* __cdecl __MINGW_NOTHROW      _wctime (const time_t* _v) { return(_wctime64 (_v)); }
251 #else
252 _CRTALIAS wchar_t* __cdecl __MINGW_NOTHROW      _wctime (const time_t* _v) { return(_wctime32 (_v)); }
253 #endif
254 #endif /* __MSVCRT_VERSION__ >= 0x0800 */
255 #endif /*  __MSVCRT__ */
256 #endif /* __STRICT_ANSI__ */
257 _CRTIMP size_t __cdecl __MINGW_NOTHROW          wcsftime (wchar_t*, size_t, const wchar_t*, const struct tm*);
258 #define _WTIME_DEFINED
259 #endif /* _WTIME_DEFINED */
260
261 _END_C_DECLS
262
263 #endif /* ! RC_INVOKED */
264 #endif /* ! _TIME_H: $RCSfile$: end of file */