]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/compat/posix/v2_0/include/sys/time.h
Initial revision
[karo-tx-redboot.git] / packages / compat / posix / v2_0 / include / sys / time.h
1 //==========================================================================
2 //
3 //      include/sys/time.h
4 //
5 //      
6 //
7 //==========================================================================
8 //####BSDCOPYRIGHTBEGIN####
9 //
10 // -------------------------------------------
11 //
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.
14 //
15 // -------------------------------------------
16 //
17 //####BSDCOPYRIGHTEND####
18 //==========================================================================
19 //#####DESCRIPTIONBEGIN####
20 //
21 // Author(s):    gthomas
22 // Contributors: gthomas
23 // Date:         2000-01-10
24 // Purpose:      
25 // Description:  
26 //              
27 //
28 //####DESCRIPTIONEND####
29 //
30 //==========================================================================
31
32
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 $        */
35
36 /*
37  * Copyright (c) 1982, 1986, 1993
38  *      The Regents of the University of California.  All rights reserved.
39  *
40  * Redistribution and use in source and binary forms, with or without
41  * modification, are permitted provided that the following conditions
42  * are met:
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.
55  *
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
66  * SUCH DAMAGE.
67  *
68  *      @(#)time.h      8.2 (Berkeley) 7/10/94
69  */
70
71 #ifndef _SYS_TIME_H_
72 #define _SYS_TIME_H_
73
74 #ifdef __cplusplus
75 extern "C" {
76 #endif
77
78 #include <sys/types.h>
79 #include <time.h>
80
81 /*
82  * Structure returned by gettimeofday(2) system call,
83  * and used in other calls.
84  */
85 struct timeval {
86         long    tv_sec;         /* seconds */
87         long    tv_usec;        /* and microseconds */
88 };
89
90
91 #define TIMEVAL_TO_TIMESPEC(tv, ts) {                                   \
92         (ts)->tv_sec = (tv)->tv_sec;                                    \
93         (ts)->tv_nsec = (tv)->tv_usec * 1000;                           \
94 }
95 #define TIMESPEC_TO_TIMEVAL(tv, ts) {                                   \
96         (tv)->tv_sec = (ts)->tv_sec;                                    \
97         (tv)->tv_usec = (ts)->tv_nsec / 1000;                           \
98 }
99
100 struct timezone {
101         int     tz_minuteswest; /* minutes west of Greenwich */
102         int     tz_dsttime;     /* type of dst correction */
103 };
104
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 */
112
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)                                         \
121         do {                                                            \
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) {                        \
125                         (vvp)->tv_sec++;                                \
126                         (vvp)->tv_usec -= 1000000;                      \
127                 }                                                       \
128         } while (0)
129 #define timersub(tvp, uvp, vvp)                                         \
130         do {                                                            \
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) {                               \
134                         (vvp)->tv_sec--;                                \
135                         (vvp)->tv_usec += 1000000;                      \
136                 }                                                       \
137         } while (0)
138
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)                                      \
147         do {                                                            \
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) {                    \
151                         (vsp)->tv_sec++;                                \
152                         (vsp)->tv_nsec -= 1000000000L;                  \
153                 }                                                       \
154         } while (0)
155 #define timespecsub(tsp, usp, vsp)                                      \
156         do {                                                            \
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) {                               \
160                         (vsp)->tv_sec--;                                \
161                         (vsp)->tv_nsec += 1000000000L;                  \
162                 }                                                       \
163         } while (0)
164
165
166 int     gettimeofday(struct timeval *, struct timezone *);
167
168 #ifdef __cplusplus
169 }
170 #endif
171
172
173 #endif