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