1 | /* |
---|
2 | * time.h |
---|
3 | * |
---|
4 | * Struct and function declarations for dealing with time. |
---|
5 | */ |
---|
6 | |
---|
7 | #ifndef _TIME_H_ |
---|
8 | #define _TIME_H_ |
---|
9 | |
---|
10 | #include "_ansi.h" |
---|
11 | #include <sys/cdefs.h> |
---|
12 | #include <sys/reent.h> |
---|
13 | |
---|
14 | #define __need_size_t |
---|
15 | #define __need_NULL |
---|
16 | #include <stddef.h> |
---|
17 | |
---|
18 | /* Get _CLOCKS_PER_SEC_ */ |
---|
19 | #include <machine/time.h> |
---|
20 | |
---|
21 | #ifndef _CLOCKS_PER_SEC_ |
---|
22 | #define _CLOCKS_PER_SEC_ 1000 |
---|
23 | #endif |
---|
24 | |
---|
25 | #define CLOCKS_PER_SEC _CLOCKS_PER_SEC_ |
---|
26 | #define CLK_TCK CLOCKS_PER_SEC |
---|
27 | |
---|
28 | #include <sys/types.h> |
---|
29 | #include <sys/timespec.h> |
---|
30 | |
---|
31 | #if __POSIX_VISIBLE >= 200809 |
---|
32 | #include <xlocale.h> |
---|
33 | #endif |
---|
34 | |
---|
35 | _BEGIN_STD_C |
---|
36 | |
---|
37 | struct tm |
---|
38 | { |
---|
39 | int tm_sec; |
---|
40 | int tm_min; |
---|
41 | int tm_hour; |
---|
42 | int tm_mday; |
---|
43 | int tm_mon; |
---|
44 | int tm_year; |
---|
45 | int tm_wday; |
---|
46 | int tm_yday; |
---|
47 | int tm_isdst; |
---|
48 | #ifdef __TM_GMTOFF |
---|
49 | long __TM_GMTOFF; |
---|
50 | #endif |
---|
51 | #ifdef __TM_ZONE |
---|
52 | const char *__TM_ZONE; |
---|
53 | #endif |
---|
54 | }; |
---|
55 | |
---|
56 | clock_t clock (void); |
---|
57 | double difftime (time_t _time2, time_t _time1); |
---|
58 | time_t mktime (struct tm *_timeptr); |
---|
59 | time_t time (time_t *_timer); |
---|
60 | #ifndef _REENT_ONLY |
---|
61 | char *asctime (const struct tm *_tblock); |
---|
62 | char *ctime (const time_t *_time); |
---|
63 | struct tm *gmtime (const time_t *_timer); |
---|
64 | struct tm *localtime (const time_t *_timer); |
---|
65 | #endif |
---|
66 | size_t strftime (char *__restrict _s, |
---|
67 | size_t _maxsize, const char *__restrict _fmt, |
---|
68 | const struct tm *__restrict _t); |
---|
69 | |
---|
70 | #if __POSIX_VISIBLE >= 200809 |
---|
71 | extern size_t strftime_l (char *__restrict _s, size_t _maxsize, |
---|
72 | const char *__restrict _fmt, |
---|
73 | const struct tm *__restrict _t, locale_t _l); |
---|
74 | #endif |
---|
75 | |
---|
76 | char *asctime_r (const struct tm *__restrict, |
---|
77 | char *__restrict); |
---|
78 | char *ctime_r (const time_t *, char *); |
---|
79 | struct tm *gmtime_r (const time_t *__restrict, |
---|
80 | struct tm *__restrict); |
---|
81 | struct tm *localtime_r (const time_t *__restrict, |
---|
82 | struct tm *__restrict); |
---|
83 | |
---|
84 | _END_STD_C |
---|
85 | |
---|
86 | #ifdef __cplusplus |
---|
87 | extern "C" { |
---|
88 | #endif |
---|
89 | |
---|
90 | #if __XSI_VISIBLE |
---|
91 | char *strptime (const char *__restrict, |
---|
92 | const char *__restrict, |
---|
93 | struct tm *__restrict); |
---|
94 | #endif |
---|
95 | #if __GNU_VISIBLE |
---|
96 | char *strptime_l (const char *__restrict, const char *__restrict, |
---|
97 | struct tm *__restrict, locale_t); |
---|
98 | #endif |
---|
99 | |
---|
100 | #if __POSIX_VISIBLE |
---|
101 | void tzset (void); |
---|
102 | #endif |
---|
103 | void _tzset_r (struct _reent *); |
---|
104 | |
---|
105 | typedef struct __tzrule_struct |
---|
106 | { |
---|
107 | char ch; |
---|
108 | int m; |
---|
109 | int n; |
---|
110 | int d; |
---|
111 | int s; |
---|
112 | time_t change; |
---|
113 | long offset; /* Match type of _timezone. */ |
---|
114 | } __tzrule_type; |
---|
115 | |
---|
116 | typedef struct __tzinfo_struct |
---|
117 | { |
---|
118 | int __tznorth; |
---|
119 | int __tzyear; |
---|
120 | __tzrule_type __tzrule[2]; |
---|
121 | } __tzinfo_type; |
---|
122 | |
---|
123 | __tzinfo_type *__gettzinfo (void); |
---|
124 | |
---|
125 | /* getdate functions */ |
---|
126 | |
---|
127 | #ifdef HAVE_GETDATE |
---|
128 | #if __XSI_VISIBLE >= 4 |
---|
129 | #ifndef _REENT_ONLY |
---|
130 | #define getdate_err (*__getdate_err()) |
---|
131 | int *__getdate_err (void); |
---|
132 | |
---|
133 | struct tm * getdate (const char *); |
---|
134 | /* getdate_err is set to one of the following values to indicate the error. |
---|
135 | 1 the DATEMSK environment variable is null or undefined, |
---|
136 | 2 the template file cannot be opened for reading, |
---|
137 | 3 failed to get file status information, |
---|
138 | 4 the template file is not a regular file, |
---|
139 | 5 an error is encountered while reading the template file, |
---|
140 | 6 memory allication failed (not enough memory available), |
---|
141 | 7 there is no line in the template that matches the input, |
---|
142 | 8 invalid input specification */ |
---|
143 | #endif /* !_REENT_ONLY */ |
---|
144 | #endif /* __XSI_VISIBLE >= 4 */ |
---|
145 | |
---|
146 | #if __GNU_VISIBLE |
---|
147 | /* getdate_r returns the error code as above */ |
---|
148 | int getdate_r (const char *, struct tm *); |
---|
149 | #endif /* __GNU_VISIBLE */ |
---|
150 | #endif /* HAVE_GETDATE */ |
---|
151 | |
---|
152 | /* defines for the opengroup specifications Derived from Issue 1 of the SVID. */ |
---|
153 | #if __SVID_VISIBLE || __XSI_VISIBLE |
---|
154 | extern __IMPORT long _timezone; |
---|
155 | extern __IMPORT int _daylight; |
---|
156 | #endif |
---|
157 | #if __POSIX_VISIBLE |
---|
158 | extern __IMPORT char *_tzname[2]; |
---|
159 | |
---|
160 | /* POSIX defines the external tzname being defined in time.h */ |
---|
161 | #ifndef tzname |
---|
162 | #define tzname _tzname |
---|
163 | #endif |
---|
164 | #endif /* __POSIX_VISIBLE */ |
---|
165 | |
---|
166 | #ifdef __cplusplus |
---|
167 | } |
---|
168 | #endif |
---|
169 | |
---|
170 | #include <sys/features.h> |
---|
171 | |
---|
172 | #ifdef __CYGWIN__ |
---|
173 | #include <cygwin/time.h> |
---|
174 | #endif /*__CYGWIN__*/ |
---|
175 | |
---|
176 | #if defined(_POSIX_TIMERS) |
---|
177 | |
---|
178 | #include <signal.h> |
---|
179 | |
---|
180 | #ifdef __cplusplus |
---|
181 | extern "C" { |
---|
182 | #endif |
---|
183 | |
---|
184 | /* Clocks, P1003.1b-1993, p. 263 */ |
---|
185 | |
---|
186 | int clock_settime (clockid_t clock_id, const struct timespec *tp); |
---|
187 | int clock_gettime (clockid_t clock_id, struct timespec *tp); |
---|
188 | int clock_getres (clockid_t clock_id, struct timespec *res); |
---|
189 | |
---|
190 | /* Create a Per-Process Timer, P1003.1b-1993, p. 264 */ |
---|
191 | |
---|
192 | int timer_create (clockid_t clock_id, |
---|
193 | struct sigevent *__restrict evp, |
---|
194 | timer_t *__restrict timerid); |
---|
195 | |
---|
196 | /* Delete a Per_process Timer, P1003.1b-1993, p. 266 */ |
---|
197 | |
---|
198 | int timer_delete (timer_t timerid); |
---|
199 | |
---|
200 | /* Per-Process Timers, P1003.1b-1993, p. 267 */ |
---|
201 | |
---|
202 | int timer_settime (timer_t timerid, int flags, |
---|
203 | const struct itimerspec *__restrict value, |
---|
204 | struct itimerspec *__restrict ovalue); |
---|
205 | int timer_gettime (timer_t timerid, struct itimerspec *value); |
---|
206 | int timer_getoverrun (timer_t timerid); |
---|
207 | |
---|
208 | /* High Resolution Sleep, P1003.1b-1993, p. 269 */ |
---|
209 | |
---|
210 | int nanosleep (const struct timespec *rqtp, struct timespec *rmtp); |
---|
211 | |
---|
212 | #ifdef __cplusplus |
---|
213 | } |
---|
214 | #endif |
---|
215 | #endif /* _POSIX_TIMERS */ |
---|
216 | |
---|
217 | #if defined(_POSIX_CLOCK_SELECTION) |
---|
218 | |
---|
219 | #ifdef __cplusplus |
---|
220 | extern "C" { |
---|
221 | #endif |
---|
222 | |
---|
223 | int clock_nanosleep (clockid_t clock_id, int flags, |
---|
224 | const struct timespec *rqtp, struct timespec *rmtp); |
---|
225 | |
---|
226 | #ifdef __cplusplus |
---|
227 | } |
---|
228 | #endif |
---|
229 | |
---|
230 | #endif /* _POSIX_CLOCK_SELECTION */ |
---|
231 | |
---|
232 | #ifdef __cplusplus |
---|
233 | extern "C" { |
---|
234 | #endif |
---|
235 | |
---|
236 | /* CPU-time Clock Attributes, P1003.4b/D8, p. 54 */ |
---|
237 | |
---|
238 | /* values for the clock enable attribute */ |
---|
239 | |
---|
240 | #define CLOCK_ENABLED 1 /* clock is enabled, i.e. counting execution time */ |
---|
241 | #define CLOCK_DISABLED 0 /* clock is disabled */ |
---|
242 | |
---|
243 | /* values for the pthread cputime_clock_allowed attribute */ |
---|
244 | |
---|
245 | #define CLOCK_ALLOWED 1 /* If a thread is created with this value a */ |
---|
246 | /* CPU-time clock attached to that thread */ |
---|
247 | /* shall be accessible. */ |
---|
248 | #define CLOCK_DISALLOWED 0 /* If a thread is created with this value, the */ |
---|
249 | /* thread shall not have a CPU-time clock */ |
---|
250 | /* accessible. */ |
---|
251 | |
---|
252 | /* Manifest Constants, P1003.1b-1993, p. 262 */ |
---|
253 | |
---|
254 | #define CLOCK_REALTIME (clockid_t)1 |
---|
255 | |
---|
256 | /* Flag indicating time is "absolute" with respect to the clock |
---|
257 | associated with a time. */ |
---|
258 | |
---|
259 | #define TIMER_ABSTIME 4 |
---|
260 | |
---|
261 | /* Manifest Constants, P1003.4b/D8, p. 55 */ |
---|
262 | |
---|
263 | #if defined(_POSIX_CPUTIME) |
---|
264 | |
---|
265 | /* When used in a clock or timer function call, this is interpreted as |
---|
266 | the identifier of the CPU_time clock associated with the PROCESS |
---|
267 | making the function call. */ |
---|
268 | |
---|
269 | #define CLOCK_PROCESS_CPUTIME_ID (clockid_t)2 |
---|
270 | |
---|
271 | #endif |
---|
272 | |
---|
273 | #if defined(_POSIX_THREAD_CPUTIME) |
---|
274 | |
---|
275 | /* When used in a clock or timer function call, this is interpreted as |
---|
276 | the identifier of the CPU_time clock associated with the THREAD |
---|
277 | making the function call. */ |
---|
278 | |
---|
279 | #define CLOCK_THREAD_CPUTIME_ID (clockid_t)3 |
---|
280 | |
---|
281 | #endif |
---|
282 | |
---|
283 | #if defined(_POSIX_MONOTONIC_CLOCK) |
---|
284 | |
---|
285 | /* The identifier for the system-wide monotonic clock, which is defined |
---|
286 | * as a clock whose value cannot be set via clock_settime() and which |
---|
287 | * cannot have backward clock jumps. */ |
---|
288 | |
---|
289 | #define CLOCK_MONOTONIC (clockid_t)4 |
---|
290 | |
---|
291 | #endif |
---|
292 | |
---|
293 | #if defined(_POSIX_CPUTIME) |
---|
294 | |
---|
295 | /* Accessing a Process CPU-time CLock, P1003.4b/D8, p. 55 */ |
---|
296 | |
---|
297 | int clock_getcpuclockid (pid_t pid, clockid_t *clock_id); |
---|
298 | |
---|
299 | #endif /* _POSIX_CPUTIME */ |
---|
300 | |
---|
301 | #if defined(_POSIX_CPUTIME) || defined(_POSIX_THREAD_CPUTIME) |
---|
302 | |
---|
303 | /* CPU-time Clock Attribute Access, P1003.4b/D8, p. 56 */ |
---|
304 | |
---|
305 | int clock_setenable_attr (clockid_t clock_id, int attr); |
---|
306 | int clock_getenable_attr (clockid_t clock_id, int *attr); |
---|
307 | |
---|
308 | #endif /* _POSIX_CPUTIME or _POSIX_THREAD_CPUTIME */ |
---|
309 | |
---|
310 | #ifdef __cplusplus |
---|
311 | } |
---|
312 | #endif |
---|
313 | |
---|
314 | #endif /* _TIME_H_ */ |
---|
315 | |
---|