1 /*
2 Copyright (c) 1991, 1993
3 The Regents of the University of California.  All rights reserved.
4 c) UNIX System Laboratories, Inc.
5 All or some portions of this file are derived from material licensed
6 to the University of California by American Telephone and Telegraph
7 Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 the permission of UNIX System Laboratories, Inc.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions
12 are met:
13 1. Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15 2. Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in the
17 documentation and/or other materials provided with the distribution.
18 3. Neither the name of the University nor the names of its contributors
19 may be used to endorse or promote products derived from this software
20 without specific prior written permission.
21 
22 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 SUCH DAMAGE.
33  */
34 /*
35  * time.h
36  *
37  * Struct and function declarations for dealing with time.
38  */
39 
40 #ifndef _TIME_H_
41 #define _TIME_H_
42 
43 #include <sys/cdefs.h>
44 
45 #define __need_size_t
46 #define __need_NULL
47 #include <stddef.h>
48 #include <sys/_types.h>
49 #include <sys/_timespec.h>
50 
51 _BEGIN_STD_C
52 
53 #ifndef _CLOCKS_PER_SEC_
54 #define _CLOCKS_PER_SEC_ 1000000
55 #endif
56 
57 #ifndef CLOCKS_PER_SEC
58 #define CLOCKS_PER_SEC _CLOCKS_PER_SEC_
59 #endif
60 
61 #ifndef TIME_UTC
62 #define TIME_UTC 1
63 #endif
64 
65 #ifndef _CLOCK_T_DECLARED
66 typedef	_CLOCK_T_	clock_t;
67 #define	_CLOCK_T_DECLARED
68 #endif
69 
70 struct tm
71 {
72   int	tm_sec;
73   int	tm_min;
74   int	tm_hour;
75   int	tm_mday;
76   int	tm_mon;
77   int	tm_year;
78   int	tm_wday;
79   int	tm_yday;
80   int	tm_isdst;
81 #ifdef __TM_GMTOFF
82   long	__TM_GMTOFF;
83 #endif
84 #ifdef __TM_ZONE
85   const char *__TM_ZONE;
86 #endif
87 };
88 
89 #if __POSIX_VISIBLE
90 
91 #ifndef CLK_TCK
92 #define CLK_TCK CLOCKS_PER_SEC
93 #endif
94 
95 #define CLOCK_REALTIME		((clockid_t) 1)
96 
97 /* Flag indicating time is "absolute" with respect to the clock
98    associated with a time.  Value 4 is historic. */
99 
100 #define TIMER_ABSTIME	4
101 
102 #include <sys/_locale.h>
103 
104 #ifndef _CLOCKID_T_DECLARED
105 typedef	__clockid_t	clockid_t;
106 #define	_CLOCKID_T_DECLARED
107 #endif
108 
109 #ifndef _TIMER_T_DECLARED
110 typedef	__timer_t	timer_t;
111 #define	_TIMER_T_DECLARED
112 #endif
113 
114 /*
115  * Structure defined by POSIX.1b to be like a itimerval, but with
116  * timespecs. Used in the timer_*() system calls.
117  */
118 struct itimerspec {
119 	struct timespec  it_interval;
120 	struct timespec  it_value;
121 };
122 
123 #endif
124 
125 #if __GNU_VISIBLE
126 #define CLOCK_REALTIME_COARSE	((clockid_t) 0)
127 #endif
128 
129 #if defined(_POSIX_CPUTIME)
130 
131 /* When used in a clock or timer function call, this is interpreted as
132    the identifier of the CPU_time clock associated with the PROCESS
133    making the function call.  */
134 
135 #define CLOCK_PROCESS_CPUTIME_ID ((clockid_t) 2)
136 
137 #endif
138 
139 #if defined(_POSIX_THREAD_CPUTIME)
140 
141 /*  When used in a clock or timer function call, this is interpreted as
142     the identifier of the CPU_time clock associated with the THREAD
143     making the function call.  */
144 
145 #define CLOCK_THREAD_CPUTIME_ID	((clockid_t) 3)
146 
147 #endif
148 
149 #if defined(_POSIX_MONOTONIC_CLOCK)
150 
151 /*  The identifier for the system-wide monotonic clock, which is defined
152  *  as a clock whose value cannot be set via clock_settime() and which
153  *  cannot have backward clock jumps. */
154 
155 #define CLOCK_MONOTONIC		((clockid_t) 4)
156 
157 #endif
158 
159 #if __GNU_VISIBLE
160 
161 #define CLOCK_MONOTONIC_RAW	((clockid_t) 5)
162 
163 #define CLOCK_MONOTONIC_COARSE	((clockid_t) 6)
164 
165 #define CLOCK_BOOTTIME		((clockid_t) 7)
166 
167 #define CLOCK_REALTIME_ALARM	((clockid_t) 8)
168 
169 #define CLOCK_BOOTTIME_ALARM	((clockid_t) 9)
170 
171 #endif
172 
173 /* defines for the opengroup specifications Derived from Issue 1 of the SVID.  */
174 #if __SVID_VISIBLE || __XSI_VISIBLE
175 extern long _timezone;
176 extern int _daylight;
177 #endif
178 
179 #if __POSIX_VISIBLE
180 extern char *tzname[2];
181 #endif /* __POSIX_VISIBLE */
182 
183 char	  *asctime (const struct tm *_tblock);
184 
185 #if __POSIX_VISIBLE
186 #define __ASCTIME_SIZE 26
187 
188 char	  *asctime_r 	(const struct tm *__restrict,
189                          char [__restrict_arr __min_size(__ASCTIME_SIZE)]);
190 #endif
191 
192 clock_t	   clock (void);
193 
194 #if defined(_POSIX_CPUTIME)
195 int        clock_getcpuclockid (pid_t pid, clockid_t *clock_id);
196 #endif /* _POSIX_CPUTIME */
197 
198 #if __POSIX_VISIBLE
199 int        clock_getres (clockid_t clock_id, struct timespec *res);
200 
201 int        clock_gettime (clockid_t clock_id, struct timespec *tp);
202 
203 int        clock_nanosleep (clockid_t clock_id, int flags,
204                             const struct timespec *rqtp,
205                             struct timespec *rmtp);
206 
207 int        clock_settime (clockid_t clock_id, const struct timespec *tp);
208 #endif
209 
210 char	  *ctime (const time_t *_time);
211 
212 #if __POSIX_VISIBLE
213 char	  *ctime_r 	(const time_t *,
214                          char [__restrict_arr __min_size(__ASCTIME_SIZE)]);
215 #endif
216 
217 double	   difftime (time_t _time2, time_t _time1);
218 
219 #if __XSI_VISIBLE >= 4
220 struct tm *getdate (const char *);
221 #endif /* __XSI_VISIBLE >= 4 */
222 
223 #if __GNU_VISIBLE
224 extern int getdate_err;
225 
226 int	   getdate_r (const char *, struct tm *);
227 #endif /* __GNU_VISIBLE */
228 
229 struct tm *gmtime (const time_t *_timer);
230 
231 #if __POSIX_VISIBLE || __ZEPHYR_VISIBLE
232 struct tm *gmtime_r (const time_t *__restrict,
233                      struct tm *__restrict);
234 #endif
235 
236 struct tm *localtime (const time_t *_timer);
237 
238 #if __POSIX_VISIBLE
239 struct tm *localtime_r 	(const time_t *__restrict,
240 				 struct tm *__restrict);
241 #endif
242 
243 time_t	   mktime (struct tm *_timeptr);
244 
245 int        nanosleep (const struct timespec  *rqtp, struct timespec *rmtp);
246 
247 size_t	   strftime (char *__restrict _s,
248                      size_t _maxsize, const char *__restrict _fmt,
249                      const struct tm *__restrict _t);
250 
251 int        timespec_get(struct timespec *_ts, int _base);
252 
253 #if __POSIX_VISIBLE
254 size_t strftime_l (char *__restrict _s, size_t _maxsize,
255 			  const char *__restrict _fmt,
256 			  const struct tm *__restrict _t, locale_t _l);
257 #endif
258 
259 #if __XSI_VISIBLE
260 char      *strptime (const char *__restrict,
261 				 const char *__restrict,
262 				 struct tm *__restrict);
263 #endif
264 #if __GNU_VISIBLE
265 char      *strptime_l (const char *__restrict, const char *__restrict,
266                        struct tm *__restrict, locale_t);
267 #endif
268 
269 time_t	   time (time_t *_timer);
270 
271 #if __BSD_VISIBLE || __SVID_VISIBLE || __GNU_VISIBLE
272 time_t	   timegm (struct tm *_timeptr);
273 #endif
274 
275 #if __POSIX_VISIBLE
276 struct sigevent;
277 int        timer_create (clockid_t clock_id,
278                          struct sigevent *__restrict evp,
279                          timer_t *__restrict timerid);
280 
281 int        timer_delete (timer_t timerid);
282 
283 int        timer_getoverrun (timer_t timerid);
284 
285 int        timer_gettime (timer_t timerid, struct itimerspec *value);
286 
287 int        timer_settime (timer_t timerid, int flags,
288                           const struct itimerspec *__restrict value,
289                           struct itimerspec *__restrict ovalue);
290 #endif
291 
292 void       tzset (void);
293 
294 #if __STDC_WANT_LIB_EXT1__ == 1
295 #include <sys/_types.h>
296 
297 #ifndef _ERRNO_T_DEFINED
298 typedef __errno_t errno_t;
299 #define _ERRNO_T_DEFINED
300 #endif
301 
302 #ifndef _RSIZE_T_DEFINED
303 typedef __rsize_t rsize_t;
304 #define _RSIZE_T_DEFINED
305 #endif
306 #endif
307 
308 _END_STD_C
309 
310 #endif /* _TIME_H_ */
311