2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
23 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
25 * Copyright (c) 1982, 1986, 1993
26 * The Regents of the University of California. All rights reserved.
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
31 * 1. Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. All advertising materials mentioning features or use of this software
37 * must display the following acknowledgement:
38 * This product includes software developed by the University of
39 * California, Berkeley and its contributors.
40 * 4. Neither the name of the University nor the names of its contributors
41 * may be used to endorse or promote products derived from this software
42 * without specific prior written permission.
44 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 * @(#)time.h 8.2 (Berkeley) 7/10/94
62 #include <sys/cdefs.h>
63 #include <sys/_types.h>
67 typedef __darwin_time_t
time_t;
72 typedef __darwin_suseconds_t suseconds_t
;
77 * Structure returned by gettimeofday(2) system call,
78 * and used in other calls.
83 time_t tv_sec
; /* seconds */
84 suseconds_t tv_usec
; /* and microseconds */
89 * Structure used as a parameter by getitimer(2) and setitimer(2) system
93 struct timeval it_interval
; /* timer interval */
94 struct timeval it_value
; /* current value */
98 * Names of the interval timers, and structure
99 * defining a timer setting.
101 #define ITIMER_REAL 0
102 #define ITIMER_VIRTUAL 1
103 #define ITIMER_PROF 2
107 * [XSI] The fd_set type shall be defined as described in <sys/select.h>.
109 * Note: We use _FD_SET to protect all select related
116 * Select uses bit masks of file descriptors in longs. These macros
117 * manipulate such bit fields (the filesystem macros use chars). The
118 * extra protection here is to permit application redefinition above
122 #define FD_SETSIZE 1024
125 #define __DARWIN_NBBY 8 /* bits in a byte */
126 #define __DARWIN_NFDBITS (sizeof(__int32_t) * __DARWIN_NBBY) /* bits per mask */
127 #define __DARWIN_howmany(x, y) (((x) + ((y) - 1)) / (y)) /* # y's == x bits? */
130 typedef struct fd_set
{
131 __int32_t fds_bits
[__DARWIN_howmany(FD_SETSIZE
, __DARWIN_NFDBITS
)];
135 #define FD_SET(n, p) ((p)->fds_bits[(n)/__DARWIN_NFDBITS] |= (1<<((n) % __DARWIN_NFDBITS)))
136 #define FD_CLR(n, p) ((p)->fds_bits[(n)/__DARWIN_NFDBITS] &= ~(1<<((n) % __DARWIN_NFDBITS)))
137 #define FD_ISSET(n, p) ((p)->fds_bits[(n)/__DARWIN_NFDBITS] & (1<<((n) % __DARWIN_NFDBITS)))
138 #if __GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 3
140 * Use the built-in bzero function instead of the library version so that
141 * we do not pollute the namespace or introduce prototype warnings.
143 #define FD_ZERO(p) __builtin_bzero(p, sizeof(*(p)))
145 #define FD_ZERO(p) bzero(p, sizeof(*(p)))
147 #ifndef _POSIX_C_SOURCE
148 #define FD_COPY(f, t) bcopy(f, t, sizeof(*(f)))
149 #endif /* !_POSIX_C_SOURCE */
151 #endif /* !_FD_SET */
154 #ifndef _POSIX_C_SOURCE
156 * Structure defined by POSIX.4 to be like a timeval.
161 time_t tv_sec
; /* seconds */
162 long tv_nsec
; /* and nanoseconds */
166 // LP64todo - should this move?
167 #include <machine/types.h> /* user_time_t */
169 /* LP64 version of struct timeval. time_t is a long and must grow when
170 * we're dealing with a 64-bit process.
171 * WARNING - keep in sync with struct timeval
173 #if __DARWIN_ALIGN_NATURAL
174 #pragma options align=natural
177 struct user_timeval
{
178 user_time_t tv_sec
; /* seconds */
179 suseconds_t tv_usec
; /* and microseconds */
182 struct user_itimerval
{
183 struct user_timeval it_interval
; /* timer interval */
184 struct user_timeval it_value
; /* current value */
187 /* LP64 version of struct timespec. time_t is a long and must grow when
188 * we're dealing with a 64-bit process.
189 * WARNING - keep in sync with struct timespec
191 struct user_timespec
{
192 user_time_t tv_sec
; /* seconds */
193 int32_t tv_nsec
; /* and nanoseconds */
196 #if __DARWIN_ALIGN_NATURAL
197 #pragma options align=reset
203 #define TIMEVAL_TO_TIMESPEC(tv, ts) { \
204 (ts)->tv_sec = (tv)->tv_sec; \
205 (ts)->tv_nsec = (tv)->tv_usec * 1000; \
207 #define TIMESPEC_TO_TIMEVAL(tv, ts) { \
208 (tv)->tv_sec = (ts)->tv_sec; \
209 (tv)->tv_usec = (ts)->tv_nsec / 1000; \
213 int tz_minuteswest
; /* minutes west of Greenwich */
214 int tz_dsttime
; /* type of dst correction */
216 #define DST_NONE 0 /* not on dst */
217 #define DST_USA 1 /* USA style dst */
218 #define DST_AUST 2 /* Australian style dst */
219 #define DST_WET 3 /* Western European dst */
220 #define DST_MET 4 /* Middle European dst */
221 #define DST_EET 5 /* Eastern European dst */
222 #define DST_CAN 6 /* Canada */
224 /* Operations on timevals. */
225 #define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0
226 #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
227 #define timercmp(tvp, uvp, cmp) \
228 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
229 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
230 ((tvp)->tv_sec cmp (uvp)->tv_sec))
231 #define timeradd(tvp, uvp, vvp) \
233 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
234 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
235 if ((vvp)->tv_usec >= 1000000) { \
237 (vvp)->tv_usec -= 1000000; \
240 #define timersub(tvp, uvp, vvp) \
242 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
243 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
244 if ((vvp)->tv_usec < 0) { \
246 (vvp)->tv_usec += 1000000; \
250 #define timevalcmp(l, r, cmp) timercmp(l, r, cmp) /* freebsd */
253 * Getkerninfo clock information structure
256 int hz
; /* clock frequency */
257 int tick
; /* micro-seconds per hz tick */
258 int tickadj
; /* clock skew rate for adjtime() */
259 int stathz
; /* statistics clock frequency */
260 int profhz
; /* profiling clock frequency */
262 #endif /* ! _POSIX_C_SOURCE */
267 #ifndef _POSIX_C_SOURCE
269 void microtime(struct timeval
*tv
);
270 void microuptime(struct timeval
*tv
);
271 #define getmicrotime(a) microtime(a)
272 #define getmicrouptime(a) microuptime(a)
273 void nanotime(struct timespec
*ts
);
274 void nanouptime(struct timespec
*ts
);
275 #define getnanotime(a) nanotime(a)
276 #define getnanouptime(a) nanouptime(a)
277 void timevaladd(struct timeval
*t1
, struct timeval
*t2
);
278 void timevalsub(struct timeval
*t1
, struct timeval
*t2
);
279 void timevalfix(struct timeval
*t1
);
280 #ifdef BSD_KERNEL_PRIVATE
281 time_t boottime_sec(void);
282 void inittodr(time_t base
);
283 int itimerfix(struct timeval
*tv
);
284 int itimerdecr(struct itimerval
*itp
, int usec
);
285 #endif /* BSD_KERNEL_PRIVATE */
289 #endif /* ! _POSIX_C_SOURCE */
295 #ifndef _POSIX_C_SOURCE
298 int adjtime(const struct timeval
*, struct timeval
*);
299 int futimes(int, const struct timeval
*);
300 int settimeofday(const struct timeval
*, const struct timezone
*);
301 #endif /* ! _POSIX_C_SOURCE */
303 int getitimer(int, struct itimerval
*);
304 int gettimeofday(struct timeval
* __restrict
, struct timezone
* __restrict
);
305 int select(int, fd_set
* __restrict
, fd_set
* __restrict
,
306 fd_set
* __restrict
, struct timeval
* __restrict
);
307 int setitimer(int, const struct itimerval
* __restrict
,
308 struct itimerval
* __restrict
);
309 int utimes(const char *, const struct timeval
*);
315 #endif /* !_SYS_TIME_H_ */