1 //==========================================================================
7 //==========================================================================
8 //####BSDCOPYRIGHTBEGIN####
10 // -------------------------------------------
12 // Portions of this software may have been derived from OpenBSD or other sources,
13 // and are covered by the appropriate copyright disclaimers included herein.
15 // -------------------------------------------
17 //####BSDCOPYRIGHTEND####
18 //==========================================================================
19 //#####DESCRIPTIONBEGIN####
22 // Contributors: gthomas
28 //####DESCRIPTIONEND####
30 //==========================================================================
33 /* $OpenBSD: time.h,v 1.9 1999/12/06 19:36:42 aaron Exp $ */
34 /* $NetBSD: time.h,v 1.18 1996/04/23 10:29:33 mycroft Exp $ */
37 * Copyright (c) 1982, 1986, 1993
38 * The Regents of the University of California. All rights reserved.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 3. All advertising materials mentioning features or use of this software
49 * must display the following acknowledgement:
50 * This product includes software developed by the University of
51 * California, Berkeley and its contributors.
52 * 4. Neither the name of the University nor the names of its contributors
53 * may be used to endorse or promote products derived from this software
54 * without specific prior written permission.
56 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
57 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
59 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
60 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
61 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
62 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
64 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
65 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * @(#)time.h 8.2 (Berkeley) 7/10/94
74 #include <sys/types.h>
77 #if 0 //ndef __time_t_defined
79 # define __time_t_defined
85 * Structure returned by gettimeofday(2) system call,
86 * and used in other calls.
89 long tv_sec; /* seconds */
90 long tv_usec; /* and microseconds */
97 * Structure defined by POSIX.1b to be like a timeval.
100 time_t tv_sec; /* seconds */
101 long tv_nsec; /* and nanoseconds */
105 #define TIMEVAL_TO_TIMESPEC(tv, ts) { \
106 (ts)->tv_sec = (tv)->tv_sec; \
107 (ts)->tv_nsec = (tv)->tv_usec * 1000; \
109 #define TIMESPEC_TO_TIMEVAL(tv, ts) { \
110 (tv)->tv_sec = (ts)->tv_sec; \
111 (tv)->tv_usec = (ts)->tv_nsec / 1000; \
115 int tz_minuteswest; /* minutes west of Greenwich */
116 int tz_dsttime; /* type of dst correction */
118 #define DST_NONE 0 /* not on dst */
119 #define DST_USA 1 /* USA style dst */
120 #define DST_AUST 2 /* Australian style dst */
121 #define DST_WET 3 /* Western European dst */
122 #define DST_MET 4 /* Middle European dst */
123 #define DST_EET 5 /* Eastern European dst */
124 #define DST_CAN 6 /* Canada */
126 /* Operations on timevals. */
127 #define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0
128 #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
129 #define timercmp(tvp, uvp, cmp) \
130 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
131 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
132 ((tvp)->tv_sec cmp (uvp)->tv_sec))
133 #define timeradd(tvp, uvp, vvp) \
135 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
136 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
137 if ((vvp)->tv_usec >= 1000000) { \
139 (vvp)->tv_usec -= 1000000; \
142 #define timersub(tvp, uvp, vvp) \
144 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
145 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
146 if ((vvp)->tv_usec < 0) { \
148 (vvp)->tv_usec += 1000000; \
152 /* Operations on timespecs. */
153 #define timespecclear(tsp) (tsp)->tv_sec = (tsp)->tv_nsec = 0
154 #define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec)
155 #define timespeccmp(tsp, usp, cmp) \
156 (((tsp)->tv_sec == (usp)->tv_sec) ? \
157 ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \
158 ((tsp)->tv_sec cmp (usp)->tv_sec))
159 #define timespecadd(tsp, usp, vsp) \
161 (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \
162 (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \
163 if ((vsp)->tv_nsec >= 1000000000L) { \
165 (vsp)->tv_nsec -= 1000000000L; \
168 #define timespecsub(tsp, usp, vsp) \
170 (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \
171 (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \
172 if ((vsp)->tv_nsec < 0) { \
174 (vsp)->tv_nsec += 1000000000L; \
179 * Names of the interval timers, and structure
180 * defining a timer setting.
182 #define ITIMER_REAL 0
183 #define ITIMER_VIRTUAL 1
184 #define ITIMER_PROF 2
187 struct timeval it_interval; /* timer interval */
188 struct timeval it_value; /* current value */
192 * Getkerninfo clock information structure
195 int hz; /* clock frequency */
196 int tick; /* micro-seconds per hz tick */
197 int tickadj; /* clock skew rate for adjtime() */
198 int stathz; /* statistics clock frequency */
199 int profhz; /* profiling clock frequency */
202 #define CLOCK_REALTIME 0
203 #define CLOCK_VIRTUAL 1
206 #define TIMER_RELTIME 0x0 /* relative timer */
207 #ifndef TIMER_ABSTIME
208 #define TIMER_ABSTIME 0x1 /* absolute timer */
211 #if defined(_KERNEL) || defined(_STANDALONE)
212 int itimerfix __P((struct timeval *tv));
213 int itimerdecr __P((struct itimerval *itp, int usec));
214 void microtime __P((struct timeval *tv));
215 void settime __P((struct timeval *tv));
222 #if 0 //ndef _POSIX_SOURCE
223 #include <sys/cdefs.h>
226 int adjtime __P((const struct timeval *, struct timeval *));
227 int clock_getres __P((clockid_t, struct timespec *));
228 int clock_gettime __P((clockid_t, struct timespec *));
229 int clock_settime __P((clockid_t, const struct timespec *));
230 int futimes __P((int, const struct timeval *));
231 int getitimer __P((int, struct itimerval *));
232 int gettimeofday __P((struct timeval *, struct timezone *));
233 int nanosleep __P((const struct timespec *, struct timespec *));
234 int setitimer __P((int, const struct itimerval *, struct itimerval *));
235 int settimeofday __P((const struct timeval *, const struct timezone *));
236 int utimes __P((const char *, const struct timeval *));
240 #endif /* !_KERNEL */
242 #endif /* !_SYS_TIME_H_ */