]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/net/bsd_tcpip/v2_0/include/sys/time.h
Initial revision
[karo-tx-redboot.git] / packages / net / bsd_tcpip / v2_0 / include / sys / time.h
1 //==========================================================================
2 //
3 //      include/sys/time.h
4 //
5 //==========================================================================
6 //####BSDCOPYRIGHTBEGIN####
7 //
8 // -------------------------------------------
9 //
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.
13 //
14 // Portions created by Red Hat are
15 // Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
16 //
17 // -------------------------------------------
18 //
19 //####BSDCOPYRIGHTEND####
20 //==========================================================================
21
22 //==========================================================================
23 //
24 //      include/sys/time.h
25 //
26 //      
27 //
28 //==========================================================================
29 //####BSDCOPYRIGHTBEGIN####
30 //
31 // -------------------------------------------
32 //
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.
35 //
36 // -------------------------------------------
37 //
38 //####BSDCOPYRIGHTEND####
39 //==========================================================================
40 //#####DESCRIPTIONBEGIN####
41 //
42 // Author(s):    gthomas
43 // Contributors: gthomas
44 // Date:         2000-01-10
45 // Purpose:      
46 // Description:  
47 //              
48 //
49 //####DESCRIPTIONEND####
50 //
51 //==========================================================================
52
53
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 $        */
56
57 /*
58  * Copyright (c) 1982, 1986, 1993
59  *      The Regents of the University of California.  All rights reserved.
60  *
61  * Redistribution and use in source and binary forms, with or without
62  * modification, are permitted provided that the following conditions
63  * are met:
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.
76  *
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
87  * SUCH DAMAGE.
88  *
89  *      @(#)time.h      8.2 (Berkeley) 7/10/94
90  */
91
92 #ifndef _SYS_TIME_H_
93 #define _SYS_TIME_H_
94
95 #include <sys/types.h>
96 #include <time.h>
97
98 #if 0 //ndef __time_t_defined
99 typedef int time_t;
100 # define __time_t_defined
101 #endif
102
103 #if 0
104
105 /*
106  * Structure returned by gettimeofday(2) system call,
107  * and used in other calls.
108  */
109 struct timeval {
110         long    tv_sec;         /* seconds */
111         long    tv_usec;        /* and microseconds */
112 };
113
114 #endif
115
116 #if 0
117 /*
118  * Structure defined by POSIX.1b to be like a timeval.
119  */
120 struct timespec {
121         time_t  tv_sec;         /* seconds */
122         long    tv_nsec;        /* and nanoseconds */
123 };
124 #endif
125
126 #define TIMEVAL_TO_TIMESPEC(tv, ts) {                                   \
127         (ts)->tv_sec = (tv)->tv_sec;                                    \
128         (ts)->tv_nsec = (tv)->tv_usec * 1000;                           \
129 }
130 #define TIMESPEC_TO_TIMEVAL(tv, ts) {                                   \
131         (tv)->tv_sec = (ts)->tv_sec;                                    \
132         (tv)->tv_usec = (ts)->tv_nsec / 1000;                           \
133 }
134
135 struct timezone {
136         int     tz_minuteswest; /* minutes west of Greenwich */
137         int     tz_dsttime;     /* type of dst correction */
138 };
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 */
146
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)                                         \
155         do {                                                            \
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) {                        \
159                         (vvp)->tv_sec++;                                \
160                         (vvp)->tv_usec -= 1000000;                      \
161                 }                                                       \
162         } while (0)
163 #define timersub(tvp, uvp, vvp)                                         \
164         do {                                                            \
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) {                               \
168                         (vvp)->tv_sec--;                                \
169                         (vvp)->tv_usec += 1000000;                      \
170                 }                                                       \
171         } while (0)
172
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)                                      \
181         do {                                                            \
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) {                    \
185                         (vsp)->tv_sec++;                                \
186                         (vsp)->tv_nsec -= 1000000000L;                  \
187                 }                                                       \
188         } while (0)
189 #define timespecsub(tsp, usp, vsp)                                      \
190         do {                                                            \
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) {                               \
194                         (vsp)->tv_sec--;                                \
195                         (vsp)->tv_nsec += 1000000000L;                  \
196                 }                                                       \
197         } while (0)
198
199 /*
200  * Names of the interval timers, and structure
201  * defining a timer setting.
202  */
203 #define ITIMER_REAL     0
204 #define ITIMER_VIRTUAL  1
205 #define ITIMER_PROF     2
206
207 struct  itimerval {
208         struct  timeval it_interval;    /* timer interval */
209         struct  timeval it_value;       /* current value */
210 };
211
212 /*
213  * Getkerninfo clock information structure
214  */
215 struct clockinfo {
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 */
221 };
222
223 #define CLOCK_REALTIME  0
224 #define CLOCK_VIRTUAL   1
225 #define CLOCK_PROF      2
226
227 #define TIMER_RELTIME   0x0     /* relative timer */
228 #ifndef TIMER_ABSTIME
229 #define TIMER_ABSTIME   0x1     /* absolute timer */
230 #endif
231
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));
237 #else /* !_KERNEL */
238
239 #ifndef __ECOS
240 #include <time.h>
241 #endif
242
243 #if 0 //ndef _POSIX_SOURCE
244 #include <sys/cdefs.h>
245
246 __BEGIN_DECLS
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 *));
258 __END_DECLS
259 #endif /* !POSIX */
260
261 #endif /* !_KERNEL */
262
263 #endif /* !_SYS_TIME_H_ */