2 * Copyright (c) 2006 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 timeval. 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 timeval
180 #if __DARWIN_ALIGN_NATURAL
181 #pragma options align=natural
184 struct user_timeval
{
185 user_time_t tv_sec
; /* seconds */
186 suseconds_t tv_usec
; /* and microseconds */
189 struct user_itimerval
{
190 struct user_timeval it_interval
; /* timer interval */
191 struct user_timeval it_value
; /* current value */
194 /* LP64 version of struct timespec. time_t is a long and must grow when
195 * we're dealing with a 64-bit process.
196 * WARNING - keep in sync with struct timespec
198 struct user_timespec
{
199 user_time_t tv_sec
; /* seconds */
200 int32_t tv_nsec
; /* and nanoseconds */
203 #if __DARWIN_ALIGN_NATURAL
204 #pragma options align=reset
210 #define TIMEVAL_TO_TIMESPEC(tv, ts) { \
211 (ts)->tv_sec = (tv)->tv_sec; \
212 (ts)->tv_nsec = (tv)->tv_usec * 1000; \
214 #define TIMESPEC_TO_TIMEVAL(tv, ts) { \
215 (tv)->tv_sec = (ts)->tv_sec; \
216 (tv)->tv_usec = (ts)->tv_nsec / 1000; \
220 int tz_minuteswest
; /* minutes west of Greenwich */
221 int tz_dsttime
; /* type of dst correction */
223 #define DST_NONE 0 /* not on dst */
224 #define DST_USA 1 /* USA style dst */
225 #define DST_AUST 2 /* Australian style dst */
226 #define DST_WET 3 /* Western European dst */
227 #define DST_MET 4 /* Middle European dst */
228 #define DST_EET 5 /* Eastern European dst */
229 #define DST_CAN 6 /* Canada */
231 /* Operations on timevals. */
232 #define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0
233 #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
234 #define timercmp(tvp, uvp, cmp) \
235 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
236 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
237 ((tvp)->tv_sec cmp (uvp)->tv_sec))
238 #define timeradd(tvp, uvp, vvp) \
240 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
241 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
242 if ((vvp)->tv_usec >= 1000000) { \
244 (vvp)->tv_usec -= 1000000; \
247 #define timersub(tvp, uvp, vvp) \
249 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
250 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
251 if ((vvp)->tv_usec < 0) { \
253 (vvp)->tv_usec += 1000000; \
257 #define timevalcmp(l, r, cmp) timercmp(l, r, cmp) /* freebsd */
260 * Getkerninfo clock information structure
263 int hz
; /* clock frequency */
264 int tick
; /* micro-seconds per hz tick */
265 int tickadj
; /* clock skew rate for adjtime() */
266 int stathz
; /* statistics clock frequency */
267 int profhz
; /* profiling clock frequency */
269 #endif /* ! _POSIX_C_SOURCE */
274 #ifndef _POSIX_C_SOURCE
276 void microtime(struct timeval
*tv
);
277 void microuptime(struct timeval
*tv
);
278 #define getmicrotime(a) microtime(a)
279 #define getmicrouptime(a) microuptime(a)
280 void nanotime(struct timespec
*ts
);
281 void nanouptime(struct timespec
*ts
);
282 #define getnanotime(a) nanotime(a)
283 #define getnanouptime(a) nanouptime(a)
284 void timevaladd(struct timeval
*t1
, struct timeval
*t2
);
285 void timevalsub(struct timeval
*t1
, struct timeval
*t2
);
286 void timevalfix(struct timeval
*t1
);
287 #ifdef BSD_KERNEL_PRIVATE
288 time_t boottime_sec(void);
289 void inittodr(time_t base
);
290 int itimerfix(struct timeval
*tv
);
291 int itimerdecr(struct itimerval
*itp
, int usec
);
292 #endif /* BSD_KERNEL_PRIVATE */
296 #endif /* ! _POSIX_C_SOURCE */
302 #ifndef _POSIX_C_SOURCE
305 int adjtime(const struct timeval
*, struct timeval
*);
306 int futimes(int, const struct timeval
*);
307 int settimeofday(const struct timeval
*, const struct timezone
*);
308 #endif /* ! _POSIX_C_SOURCE */
310 int getitimer(int, struct itimerval
*);
311 int gettimeofday(struct timeval
* __restrict
, struct timezone
* __restrict
);
312 int select(int, fd_set
* __restrict
, fd_set
* __restrict
,
313 fd_set
* __restrict
, struct timeval
* __restrict
);
314 int setitimer(int, const struct itimerval
* __restrict
,
315 struct itimerval
* __restrict
);
316 int utimes(const char *, const struct timeval
*);
322 #endif /* !_SYS_TIME_H_ */