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
78 #include <sys/types.h>
82 * Structure returned by gettimeofday(2) system call,
83 * and used in other calls.
86 long tv_sec; /* seconds */
87 long tv_usec; /* and microseconds */
91 #define TIMEVAL_TO_TIMESPEC(tv, ts) { \
92 (ts)->tv_sec = (tv)->tv_sec; \
93 (ts)->tv_nsec = (tv)->tv_usec * 1000; \
95 #define TIMESPEC_TO_TIMEVAL(tv, ts) { \
96 (tv)->tv_sec = (ts)->tv_sec; \
97 (tv)->tv_usec = (ts)->tv_nsec / 1000; \
101 int tz_minuteswest; /* minutes west of Greenwich */
102 int tz_dsttime; /* type of dst correction */
105 #define DST_NONE 0 /* not on dst */
106 #define DST_USA 1 /* USA style dst */
107 #define DST_AUST 2 /* Australian style dst */
108 #define DST_WET 3 /* Western European dst */
109 #define DST_MET 4 /* Middle European dst */
110 #define DST_EET 5 /* Eastern European dst */
111 #define DST_CAN 6 /* Canada */
113 /* Operations on timevals. */
114 #define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0
115 #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
116 #define timercmp(tvp, uvp, cmp) \
117 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
118 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
119 ((tvp)->tv_sec cmp (uvp)->tv_sec))
120 #define timeradd(tvp, uvp, vvp) \
122 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
123 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
124 if ((vvp)->tv_usec >= 1000000) { \
126 (vvp)->tv_usec -= 1000000; \
129 #define timersub(tvp, uvp, vvp) \
131 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
132 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
133 if ((vvp)->tv_usec < 0) { \
135 (vvp)->tv_usec += 1000000; \
139 /* Operations on timespecs. */
140 #define timespecclear(tsp) (tsp)->tv_sec = (tsp)->tv_nsec = 0
141 #define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec)
142 #define timespeccmp(tsp, usp, cmp) \
143 (((tsp)->tv_sec == (usp)->tv_sec) ? \
144 ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \
145 ((tsp)->tv_sec cmp (usp)->tv_sec))
146 #define timespecadd(tsp, usp, vsp) \
148 (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \
149 (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \
150 if ((vsp)->tv_nsec >= 1000000000L) { \
152 (vsp)->tv_nsec -= 1000000000L; \
155 #define timespecsub(tsp, usp, vsp) \
157 (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \
158 (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \
159 if ((vsp)->tv_nsec < 0) { \
161 (vsp)->tv_nsec += 1000000000L; \
166 int gettimeofday(struct timeval *, struct timezone *);