|
0
|
1 #ifndef CYGONCE_LIBC_TIME_H |
|
|
2 #define CYGONCE_LIBC_TIME_H |
|
|
3 //=========================================================================== |
|
|
4 // |
|
|
5 // time.h |
|
|
6 // |
|
2
|
7 // Date and time routines from ISO C section 7.12 and POSIX 1003.1 |
|
0
|
8 // |
|
|
9 //=========================================================================== |
|
|
10 //####COPYRIGHTBEGIN#### |
|
|
11 // |
|
|
12 // ------------------------------------------- |
|
|
13 // The contents of this file are subject to the Cygnus eCos Public License |
|
|
14 // Version 1.0 (the "License"); you may not use this file except in |
|
|
15 // compliance with the License. You may obtain a copy of the License at |
|
|
16 // http://sourceware.cygnus.com/ecos |
|
|
17 // |
|
|
18 // Software distributed under the License is distributed on an "AS IS" |
|
|
19 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
|
20 // License for the specific language governing rights and limitations under |
|
|
21 // the License. |
|
|
22 // |
|
|
23 // The Original Code is eCos - Embedded Cygnus Operating System, released |
|
|
24 // September 30, 1998. |
|
|
25 // |
|
|
26 // The Initial Developer of the Original Code is Cygnus. Portions created |
|
2
|
27 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
|
0
|
28 // ------------------------------------------- |
|
|
29 // |
|
|
30 //####COPYRIGHTEND#### |
|
|
31 //=========================================================================== |
|
|
32 //#####DESCRIPTIONBEGIN#### |
|
|
33 // |
|
2
|
34 // Author(s): jlarmour |
|
|
35 // Contributors: jlarmour |
|
|
36 // Date: 1999-02-25 |
|
|
37 // Purpose: Provide definitions required by ISO C section 7.12 and |
|
|
38 // POSIX 1003.1 8.3.4-8.3.7 |
|
0
|
39 // Description: |
|
2
|
40 // Usage: #include <time.h> |
|
0
|
41 // |
|
|
42 //####DESCRIPTIONEND#### |
|
|
43 // |
|
|
44 //=========================================================================== |
|
|
45 |
|
|
46 // CONFIGURATION |
|
|
47 |
|
2
|
48 #include <pkgconf/libc.h> // C library configuration |
|
0
|
49 |
|
|
50 // INCLUDES |
|
|
51 |
|
2
|
52 #include <cyg/infra/cyg_type.h> // Common type definitions and support |
|
|
53 #include <stddef.h> // <time.h> is required to provide NULL |
|
|
54 // and size_t, so we get them from compiler |
|
0
|
55 |
|
|
56 // CONSTANTS |
|
|
57 |
|
|
58 // What to divide clock_t by to get seconds (para 7.12.1) |
|
2
|
59 // According to CAE XSH, Issue 4, V2, CLOCKS_PER_SEC must be 1 million on all |
|
|
60 // XSI-conformant systems |
|
|
61 #define CLOCKS_PER_SEC 1000000 |
|
0
|
62 |
|
|
63 // TYPE DEFINITIONS |
|
|
64 |
|
2
|
65 // Define clock_t as per ISO C para 7.12.1 |
|
|
66 // We make it very big since CLOCKS_PER_SEC is so large - this should last |
|
|
67 // for 584942 years :-) An int32 would only last a little over an hour :-( |
|
0
|
68 typedef cyg_int64 clock_t; |
|
|
69 |
|
2
|
70 // Define time_t as per ISO C para 7.12.1 |
|
|
71 // In the implementation we give it the meaning of seconds since the |
|
|
72 // Epoch (00:00:00 GMT, 1970-01-01), but don't rely on this - always use |
|
|
73 // the type opaquely |
|
|
74 // A 32-bit value will overflow in the year 2038. Hopefully we will have |
|
|
75 // moved forward from 32-bit CPUs by then, so making it a cyg_count* type |
|
|
76 // may suffice ;-) |
|
0
|
77 typedef cyg_count32 time_t; |
|
2
|
78 #define __time_t_defined // FIXME: this is temporary to stop newlib's |
|
|
79 // <sys/types.h> complaining. This should be resolved |
|
|
80 // properly and a new <sys/types.h> provided |
|
0
|
81 |
|
2
|
82 // Define struct tm as per ISO C para 7.12.1 |
|
0
|
83 struct tm { |
|
2
|
84 int tm_sec; // seconds after the minute - [0..61] |
|
|
85 // (note 61 allows for two leap seconds) |
|
0
|
86 int tm_min; // minutes after the hour - [0..59] |
|
|
87 int tm_hour; // hours since midnight - [0..23] |
|
|
88 int tm_mday; // days of the month - [1..31] |
|
|
89 int tm_mon; // months since January - [0..11] |
|
|
90 int tm_year; // years since 1900 |
|
|
91 int tm_wday; // days since Sunday - [0..6] |
|
|
92 int tm_yday; // days since January 1 - [0..365] |
|
|
93 int tm_isdst; // Daylight Saving Time flag - positive if DST is in |
|
|
94 // effect, 0 if not in effect, and negative if the info |
|
|
95 // is not available |
|
|
96 }; |
|
|
97 |
|
2
|
98 // The following struct is used by the implementation-defined functions |
|
|
99 // to manipulate the Daylight Savings Time state |
|
|
100 typedef enum { |
|
|
101 CYG_LIBC_TIME_DSTNA = -1, |
|
|
102 CYG_LIBC_TIME_DSTOFF = 0, |
|
|
103 CYG_LIBC_TIME_DSTON = 1 |
|
|
104 } Cyg_libc_time_dst; |
|
|
105 |
|
0
|
106 // FUNCTION PROTOTYPES |
|
|
107 |
|
2
|
108 #ifdef __cplusplus |
|
|
109 extern "C" { |
|
|
110 #endif |
|
|
111 |
|
|
112 //=========================================================================== |
|
|
113 // |
|
|
114 // POSIX 1003.1 functions |
|
|
115 |
|
|
116 #ifdef CYGFUN_LIBC_TIME_POSIX |
|
|
117 |
|
|
118 ///////////////////////////////// |
|
|
119 // asctime_r() - POSIX.1 8.3.4 // |
|
|
120 ///////////////////////////////// |
|
|
121 // |
|
|
122 // This returns a textual representation of a struct tm, and writes |
|
|
123 // the string to return into __buf |
|
|
124 // |
|
|
125 |
|
|
126 extern char * |
|
|
127 asctime_r( const struct tm *__timeptr, char *__buf ); |
|
|
128 |
|
|
129 /////////////////////////////// |
|
|
130 // ctime_r() - POSIX.1 8.3.5 // |
|
|
131 /////////////////////////////// |
|
|
132 // |
|
|
133 // This returns the equivalent of ctime() but writes to __buf |
|
|
134 // to store the returned string |
|
|
135 // |
|
|
136 |
|
|
137 extern char * |
|
|
138 ctime_r( const time_t *__timer, char *__buf ); |
|
|
139 |
|
|
140 //////////////////////////////// |
|
|
141 // gmtime_r() - POSIX.1 8.3.6 // |
|
|
142 //////////////////////////////// |
|
|
143 // |
|
|
144 // This converts a time_t into a struct tm expressed in UTC, and stores |
|
|
145 // the result in the space occupied by __result |
|
|
146 // |
|
|
147 |
|
|
148 extern struct tm * |
|
|
149 gmtime_r( const time_t *__timer, struct tm *__result ); |
|
|
150 |
|
|
151 /////////////////////////////////// |
|
|
152 // localtime_r() - POSIX.1 8.3.7 // |
|
|
153 /////////////////////////////////// |
|
|
154 // |
|
|
155 // This converts a time_t into a struct tm expressed in local time, and |
|
|
156 // stores the result in the space occupied by __result |
|
|
157 // |
|
|
158 |
|
|
159 extern struct tm * |
|
|
160 localtime_r( const time_t *__timer, struct tm *__result ); |
|
|
161 |
|
|
162 |
|
|
163 #endif // ifdef CYGFUN_LIBC_TIME_POSIX |
|
|
164 |
|
0
|
165 //=========================================================================== |
|
|
166 |
|
2
|
167 // ISO C functions |
|
|
168 |
|
|
169 // Time manipulation functions - ISO C 7.12.2 |
|
0
|
170 |
|
2
|
171 ////////////////////////////// |
|
|
172 // clock() - ISO C 7.12.2.1 // |
|
|
173 ////////////////////////////// |
|
|
174 // |
|
|
175 // Returns processor time used in "clock"s. For a single process, |
|
|
176 // multi-threaded system this will just be the time since booting |
|
|
177 // |
|
|
178 |
|
|
179 extern clock_t |
|
0
|
180 clock( void ); |
|
|
181 |
|
2
|
182 ///////////////////////////////// |
|
|
183 // difftime() - ISO C 7.12.2.2 // |
|
|
184 ///////////////////////////////// |
|
|
185 // |
|
|
186 // This returns (__time1 - __time0) in seconds |
|
|
187 // |
|
|
188 |
|
|
189 extern double |
|
|
190 difftime( time_t __time1, time_t __time0 ); |
|
|
191 |
|
|
192 /////////////////////////////// |
|
|
193 // mktime() - ISO C 7.12.2.3 // |
|
|
194 /////////////////////////////// |
|
|
195 // |
|
|
196 // This converts a "struct tm" to a "time_t" |
|
|
197 // |
|
|
198 |
|
|
199 extern time_t |
|
|
200 mktime( struct tm *__timeptr ); |
|
|
201 |
|
|
202 ///////////////////////////// |
|
|
203 // time() - ISO C 7.12.2.4 // |
|
|
204 ///////////////////////////// |
|
|
205 // |
|
|
206 // This returns calendar time as a time_t |
|
|
207 // |
|
|
208 |
|
|
209 extern time_t |
|
|
210 time( time_t *__timer ); |
|
|
211 |
|
|
212 // Time conversion functions - ISO C 7.12.3 |
|
|
213 |
|
|
214 //////////////////////////////// |
|
|
215 // asctime() - ISO C 7.12.3.1 // |
|
|
216 //////////////////////////////// |
|
|
217 // |
|
|
218 // This returns a textual representation of a struct tm |
|
|
219 // |
|
|
220 |
|
|
221 extern char * |
|
|
222 asctime( const struct tm *__timeptr ); |
|
|
223 |
|
|
224 ////////////////////////////// |
|
|
225 // ctime() - ISO C 7.12.3.2 // |
|
|
226 ////////////////////////////// |
|
|
227 // |
|
|
228 // This returns asctime(localtime(__timeptr)) |
|
|
229 // |
|
|
230 |
|
|
231 extern char * |
|
|
232 ctime( const time_t *__timer ); |
|
|
233 |
|
|
234 /////////////////////////////// |
|
|
235 // gmtime() - ISO C 7.12.3.3 // |
|
|
236 /////////////////////////////// |
|
|
237 // |
|
|
238 // This converts a time_t into a struct tm expressed in UTC |
|
|
239 // |
|
|
240 |
|
|
241 extern struct tm * |
|
|
242 gmtime( const time_t *__timer ); |
|
|
243 |
|
|
244 ////////////////////////////////// |
|
|
245 // localtime() - ISO C 7.12.3.4 // |
|
|
246 ////////////////////////////////// |
|
|
247 // |
|
|
248 // This converts a time_t into a struct tm expressed in local time |
|
|
249 // |
|
|
250 |
|
|
251 extern struct tm * |
|
|
252 localtime( const time_t *__timer ); |
|
|
253 |
|
|
254 ///////////////////////////////// |
|
|
255 // strftime() - ISO C 7.12.3.5 // |
|
|
256 ///////////////////////////////// |
|
|
257 // |
|
|
258 // This converts a string using format specifiers that signify various |
|
|
259 // time-related quantities |
|
|
260 // |
|
|
261 |
|
|
262 extern size_t |
|
|
263 strftime( char *__s, size_t __maxsize, const char *__format, |
|
|
264 const struct tm *__timeptr) CYGPRI_LIBC_ATTRIB_FORMAT_STRFTIME; |
|
|
265 |
|
|
266 //=========================================================================== |
|
|
267 |
|
|
268 // Implementation-specific functions |
|
|
269 |
|
|
270 //////////////////////////////////// |
|
|
271 // cyg_libc_time_setzoneoffsets() // |
|
|
272 //////////////////////////////////// |
|
|
273 // |
|
|
274 // This function sets the offsets used when Daylight Savings Time is enabled |
|
|
275 // or disabled. The offsets are in time_t's |
|
|
276 // |
|
|
277 |
|
|
278 extern void |
|
|
279 cyg_libc_time_setzoneoffsets( time_t __stdoffset, time_t __dstoffset ); |
|
|
280 |
|
|
281 //////////////////////////// |
|
|
282 // cyg_libc_time_setdst() // |
|
|
283 //////////////////////////// |
|
|
284 // |
|
|
285 // This function sets the state of Daylight Savings Time: on, off, or unknown |
|
|
286 // |
|
|
287 |
|
|
288 extern void |
|
|
289 cyg_libc_time_setdst( Cyg_libc_time_dst __state ); |
|
|
290 |
|
|
291 |
|
|
292 //////////////////////////////////// |
|
|
293 // cyg_libc_time_getzoneoffsets() // |
|
|
294 //////////////////////////////////// |
|
|
295 // |
|
|
296 // This function retrieves the current state of the Daylight Savings Time |
|
|
297 // and the offsets of both STD and DST |
|
|
298 // The offsets are both in time_t's |
|
|
299 // |
|
|
300 |
|
|
301 extern Cyg_libc_time_dst |
|
|
302 cyg_libc_time_getzoneoffsets( time_t *__stdoffset, time_t *__dstoffset ); |
|
|
303 |
|
|
304 ///////////////////////////// |
|
|
305 // cyg_libc_time_settime() // |
|
|
306 ///////////////////////////// |
|
|
307 // |
|
|
308 // This function sets the current time for the system. The time is |
|
|
309 // specified as a time_t in UTC. It returns non-zero on error. |
|
|
310 // |
|
|
311 |
|
|
312 extern cyg_bool |
|
|
313 cyg_libc_time_settime( time_t __utctime ); |
|
|
314 |
|
|
315 |
|
|
316 #ifdef __cplusplus |
|
|
317 } // extern "C" |
|
|
318 #endif |
|
|
319 |
|
|
320 #include <time.inl> |
|
0
|
321 |
|
|
322 #endif // CYGONCE_LIBC_TIME_H multiple inclusion protection |
|
|
323 |
|
|
324 // EOF time.h |