1 //==========================================================================
5 //==========================================================================
6 //####BSDCOPYRIGHTBEGIN####
8 // -------------------------------------------
10 // Portions of this software may have been derived from OpenBSD,
11 // FreeBSD or other sources, and are covered by the appropriate
12 // copyright disclaimers included herein.
14 // Portions created by Red Hat are
15 // Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
17 // -------------------------------------------
19 //####BSDCOPYRIGHTEND####
20 //==========================================================================
22 //==========================================================================
28 //==========================================================================
29 //####BSDCOPYRIGHTBEGIN####
31 // -------------------------------------------
33 // Portions of this software may have been derived from OpenBSD or other sources,
34 // and are covered by the appropriate copyright disclaimers included herein.
36 // -------------------------------------------
38 //####BSDCOPYRIGHTEND####
39 //==========================================================================
40 //#####DESCRIPTIONBEGIN####
43 // Contributors: gthomas
49 //####DESCRIPTIONEND####
51 //==========================================================================
54 /* $OpenBSD: time.h,v 1.9 1999/12/06 19:36:42 aaron Exp $ */
55 /* $NetBSD: time.h,v 1.18 1996/04/23 10:29:33 mycroft Exp $ */
58 * Copyright (c) 1982, 1986, 1993
59 * The Regents of the University of California. All rights reserved.
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
64 * 1. Redistributions of source code must retain the above copyright
65 * notice, this list of conditions and the following disclaimer.
66 * 2. Redistributions in binary form must reproduce the above copyright
67 * notice, this list of conditions and the following disclaimer in the
68 * documentation and/or other materials provided with the distribution.
69 * 3. All advertising materials mentioning features or use of this software
70 * must display the following acknowledgement:
71 * This product includes software developed by the University of
72 * California, Berkeley and its contributors.
73 * 4. Neither the name of the University nor the names of its contributors
74 * may be used to endorse or promote products derived from this software
75 * without specific prior written permission.
77 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
78 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
79 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
80 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
81 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
82 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
83 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
84 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
85 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
86 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
89 * @(#)time.h 8.2 (Berkeley) 7/10/94
95 #include <sys/types.h>
98 #if 0 //ndef __time_t_defined
100 # define __time_t_defined
106 * Structure returned by gettimeofday(2) system call,
107 * and used in other calls.
110 long tv_sec; /* seconds */
111 long tv_usec; /* and microseconds */
118 * Structure defined by POSIX.1b to be like a timeval.
121 time_t tv_sec; /* seconds */
122 long tv_nsec; /* and nanoseconds */
126 #define TIMEVAL_TO_TIMESPEC(tv, ts) { \
127 (ts)->tv_sec = (tv)->tv_sec; \
128 (ts)->tv_nsec = (tv)->tv_usec * 1000; \
130 #define TIMESPEC_TO_TIMEVAL(tv, ts) { \
131 (tv)->tv_sec = (ts)->tv_sec; \
132 (tv)->tv_usec = (ts)->tv_nsec / 1000; \
136 int tz_minuteswest; /* minutes west of Greenwich */
137 int tz_dsttime; /* type of dst correction */
139 #define DST_NONE 0 /* not on dst */
140 #define DST_USA 1 /* USA style dst */
141 #define DST_AUST 2 /* Australian style dst */
142 #define DST_WET 3 /* Western European dst */
143 #define DST_MET 4 /* Middle European dst */
144 #define DST_EET 5 /* Eastern European dst */
145 #define DST_CAN 6 /* Canada */
147 /* Operations on timevals. */
148 #define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0
149 #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
150 #define timercmp(tvp, uvp, cmp) \
151 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
152 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
153 ((tvp)->tv_sec cmp (uvp)->tv_sec))
154 #define timeradd(tvp, uvp, vvp) \
156 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
157 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
158 if ((vvp)->tv_usec >= 1000000) { \
160 (vvp)->tv_usec -= 1000000; \
163 #define timersub(tvp, uvp, vvp) \
165 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
166 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
167 if ((vvp)->tv_usec < 0) { \
169 (vvp)->tv_usec += 1000000; \
173 /* Operations on timespecs. */
174 #define timespecclear(tsp) (tsp)->tv_sec = (tsp)->tv_nsec = 0
175 #define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec)
176 #define timespeccmp(tsp, usp, cmp) \
177 (((tsp)->tv_sec == (usp)->tv_sec) ? \
178 ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \
179 ((tsp)->tv_sec cmp (usp)->tv_sec))
180 #define timespecadd(tsp, usp, vsp) \
182 (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \
183 (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \
184 if ((vsp)->tv_nsec >= 1000000000L) { \
186 (vsp)->tv_nsec -= 1000000000L; \
189 #define timespecsub(tsp, usp, vsp) \
191 (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \
192 (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \
193 if ((vsp)->tv_nsec < 0) { \
195 (vsp)->tv_nsec += 1000000000L; \
200 * Names of the interval timers, and structure
201 * defining a timer setting.
203 #define ITIMER_REAL 0
204 #define ITIMER_VIRTUAL 1
205 #define ITIMER_PROF 2
208 struct timeval it_interval; /* timer interval */
209 struct timeval it_value; /* current value */
213 * Getkerninfo clock information structure
216 int hz; /* clock frequency */
217 int tick; /* micro-seconds per hz tick */
218 int tickadj; /* clock skew rate for adjtime() */
219 int stathz; /* statistics clock frequency */
220 int profhz; /* profiling clock frequency */
223 #define CLOCK_REALTIME 0
224 #define CLOCK_VIRTUAL 1
227 #define TIMER_RELTIME 0x0 /* relative timer */
228 #ifndef TIMER_ABSTIME
229 #define TIMER_ABSTIME 0x1 /* absolute timer */
232 #if defined(_KERNEL) || defined(_STANDALONE)
233 int itimerfix __P((struct timeval *tv));
234 int itimerdecr __P((struct itimerval *itp, int usec));
235 void microtime __P((struct timeval *tv));
236 void settime __P((struct timeval *tv));
243 #if 0 //ndef _POSIX_SOURCE
244 #include <sys/cdefs.h>
247 int adjtime __P((const struct timeval *, struct timeval *));
248 int clock_getres __P((clockid_t, struct timespec *));
249 int clock_gettime __P((clockid_t, struct timespec *));
250 int clock_settime __P((clockid_t, const struct timespec *));
251 int futimes __P((int, const struct timeval *));
252 int getitimer __P((int, struct itimerval *));
253 int gettimeofday __P((struct timeval *, struct timezone *));
254 int nanosleep __P((const struct timespec *, struct timespec *));
255 int setitimer __P((int, const struct itimerval *, struct itimerval *));
256 int settimeofday __P((const struct timeval *, const struct timezone *));
257 int utimes __P((const char *, const struct timeval *));
261 #endif /* !_KERNEL */
263 #endif /* !_SYS_TIME_H_ */