2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
32 * Copyright (c) 1982, 1986, 1993
33 * The Regents of the University of California. All rights reserved.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. All advertising materials mentioning features or use of this software
44 * must display the following acknowledgement:
45 * This product includes software developed by the University of
46 * California, Berkeley and its contributors.
47 * 4. Neither the name of the University nor the names of its contributors
48 * may be used to endorse or promote products derived from this software
49 * without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * @(#)time.h 8.2 (Berkeley) 7/10/94
69 #include <sys/cdefs.h>
70 #include <sys/_types.h>
74 typedef __darwin_time_t
time_t;
79 typedef __darwin_suseconds_t suseconds_t
;
84 * Structure returned by gettimeofday(2) system call,
85 * and used in other calls.
90 time_t tv_sec
; /* seconds */
91 suseconds_t tv_usec
; /* and microseconds */
96 * Structure used as a parameter by getitimer(2) and setitimer(2) system
100 struct timeval it_interval
; /* timer interval */
101 struct timeval it_value
; /* current value */
105 * Names of the interval timers, and structure
106 * defining a timer setting.
108 #define ITIMER_REAL 0
109 #define ITIMER_VIRTUAL 1
110 #define ITIMER_PROF 2
114 * [XSI] The fd_set type shall be defined as described in <sys/select.h>.
116 * Note: We use _FD_SET to protect all select related
123 * Select uses bit masks of file descriptors in longs. These macros
124 * manipulate such bit fields (the filesystem macros use chars). The
125 * extra protection here is to permit application redefinition above
129 #define FD_SETSIZE 1024
132 #define __DARWIN_NBBY 8 /* bits in a byte */
133 #define __DARWIN_NFDBITS (sizeof(__int32_t) * __DARWIN_NBBY) /* bits per mask */
134 #define __DARWIN_howmany(x, y) (((x) + ((y) - 1)) / (y)) /* # y's == x bits? */
137 typedef struct fd_set
{
138 __int32_t fds_bits
[__DARWIN_howmany(FD_SETSIZE
, __DARWIN_NFDBITS
)];
142 #define FD_SET(n, p) ((p)->fds_bits[(n)/__DARWIN_NFDBITS] |= (1<<((n) % __DARWIN_NFDBITS)))
143 #define FD_CLR(n, p) ((p)->fds_bits[(n)/__DARWIN_NFDBITS] &= ~(1<<((n) % __DARWIN_NFDBITS)))
144 #define FD_ISSET(n, p) ((p)->fds_bits[(n)/__DARWIN_NFDBITS] & (1<<((n) % __DARWIN_NFDBITS)))
145 #if __GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 3
147 * Use the built-in bzero function instead of the library version so that
148 * we do not pollute the namespace or introduce prototype warnings.
150 #define FD_ZERO(p) __builtin_bzero(p, sizeof(*(p)))
152 #define FD_ZERO(p) bzero(p, sizeof(*(p)))
154 #ifndef _POSIX_C_SOURCE
155 #define FD_COPY(f, t) bcopy(f, t, sizeof(*(f)))
156 #endif /* !_POSIX_C_SOURCE */
158 #endif /* !_FD_SET */
161 #ifndef _POSIX_C_SOURCE
163 * Structure defined by POSIX.4 to be like a timeval.
168 time_t tv_sec
; /* seconds */
169 long tv_nsec
; /* and nanoseconds */
173 // LP64todo - should this move?
174 #include <machine/types.h> /* user_time_t */
176 /* LP64 version of struct timespec. time_t is a long and must grow when
177 * we're dealing with a 64-bit process.
178 * WARNING - keep in sync with struct timespec
180 struct user_timespec
{
181 user_time_t tv_sec
; /* seconds */
182 int32_t tv_nsec
__attribute((aligned(8))); /* and nanoseconds */
193 #include <machine/types.h> /* user_time_t */
195 * LP64 version of struct timeval. time_t is a long and must grow when
196 * we're dealing with a 64-bit process.
197 * WARNING - keep in sync with struct timeval
200 struct user_timeval
{
201 user_time_t tv_sec
; /* seconds */
202 suseconds_t tv_usec
__attribute((aligned(8))); /* and microseconds */
205 struct user_itimerval
{
206 struct user_timeval it_interval
; /* timer interval */
207 struct user_timeval it_value
; /* current value */
214 #define TIMEVAL_TO_TIMESPEC(tv, ts) { \
215 (ts)->tv_sec = (tv)->tv_sec; \
216 (ts)->tv_nsec = (tv)->tv_usec * 1000; \
218 #define TIMESPEC_TO_TIMEVAL(tv, ts) { \
219 (tv)->tv_sec = (ts)->tv_sec; \
220 (tv)->tv_usec = (ts)->tv_nsec / 1000; \
224 int tz_minuteswest
; /* minutes west of Greenwich */
225 int tz_dsttime
; /* type of dst correction */
227 #define DST_NONE 0 /* not on dst */
228 #define DST_USA 1 /* USA style dst */
229 #define DST_AUST 2 /* Australian style dst */
230 #define DST_WET 3 /* Western European dst */
231 #define DST_MET 4 /* Middle European dst */
232 #define DST_EET 5 /* Eastern European dst */
233 #define DST_CAN 6 /* Canada */
235 /* Operations on timevals. */
236 #define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0
237 #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
238 #define timercmp(tvp, uvp, cmp) \
239 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
240 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
241 ((tvp)->tv_sec cmp (uvp)->tv_sec))
242 #define timeradd(tvp, uvp, vvp) \
244 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
245 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
246 if ((vvp)->tv_usec >= 1000000) { \
248 (vvp)->tv_usec -= 1000000; \
251 #define timersub(tvp, uvp, vvp) \
253 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
254 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
255 if ((vvp)->tv_usec < 0) { \
257 (vvp)->tv_usec += 1000000; \
261 #define timevalcmp(l, r, cmp) timercmp(l, r, cmp) /* freebsd */
264 * Getkerninfo clock information structure
267 int hz
; /* clock frequency */
268 int tick
; /* micro-seconds per hz tick */
269 int tickadj
; /* clock skew rate for adjtime() */
270 int stathz
; /* statistics clock frequency */
271 int profhz
; /* profiling clock frequency */
273 #endif /* ! _POSIX_C_SOURCE */
278 #ifndef _POSIX_C_SOURCE
280 void microtime(struct timeval
*tv
);
281 void microuptime(struct timeval
*tv
);
282 #define getmicrotime(a) microtime(a)
283 #define getmicrouptime(a) microuptime(a)
284 void nanotime(struct timespec
*ts
);
285 void nanouptime(struct timespec
*ts
);
286 #define getnanotime(a) nanotime(a)
287 #define getnanouptime(a) nanouptime(a)
288 void timevaladd(struct timeval
*t1
, struct timeval
*t2
);
289 void timevalsub(struct timeval
*t1
, struct timeval
*t2
);
290 void timevalfix(struct timeval
*t1
);
291 #ifdef BSD_KERNEL_PRIVATE
292 time_t boottime_sec(void);
293 void inittodr(time_t base
);
294 int itimerfix(struct timeval
*tv
);
295 int itimerdecr(struct itimerval
*itp
, int usec
);
296 #endif /* BSD_KERNEL_PRIVATE */
300 #endif /* ! _POSIX_C_SOURCE */
306 #ifndef _POSIX_C_SOURCE
309 int adjtime(const struct timeval
*, struct timeval
*);
310 int futimes(int, const struct timeval
*);
311 int settimeofday(const struct timeval
*, const struct timezone
*);
312 #endif /* ! _POSIX_C_SOURCE */
314 int getitimer(int, struct itimerval
*);
315 int gettimeofday(struct timeval
* __restrict
, struct timezone
* __restrict
);
316 int select(int, fd_set
* __restrict
, fd_set
* __restrict
,
317 fd_set
* __restrict
, struct timeval
* __restrict
);
318 int setitimer(int, const struct itimerval
* __restrict
,
319 struct itimerval
* __restrict
);
320 int utimes(const char *, const struct timeval
*);
326 #endif /* !_SYS_TIME_H_ */