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