1 /* $NetBSD: time_types.h,v 1.1 2009/11/05 16:59:01 pooka Exp $ */
2
3 /*
4 * Copyright (c) 1982, 1986, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * @(#)time.h 8.5 (Berkeley) 5/4/95
32 */
33
34 #ifndef _COMPAT_SYS_TIME_TYPES_H_
35 #define _COMPAT_SYS_TIME_TYPES_H_
36
37 /*
38 * Structure returned by gettimeofday(2) system call,
39 * and used in other calls.
40 */
41 struct timeval50 {
42 long tv_sec; /* seconds */
43 long tv_usec; /* and microseconds */
44 };
45
46 struct itimerval50 {
47 struct timeval50 it_interval; /* timer interval */
48 struct timeval50 it_value; /* current value */
49 };
50
51 /*
52 * Structure defined by POSIX.1b to be like a timeval.
53 */
54 struct timespec50 {
55 int32_t tv_sec; /* seconds */
56 long tv_nsec; /* and nanoseconds */
57 };
58
59 /*
60 * Structure defined by POSIX.1b to be like a itimerval, but with
61 * timespecs. Used in the timer_*() system calls.
62 */
63 struct itimerspec50 {
64 struct timespec50 it_interval;
65 struct timespec50 it_value;
66 };
67
timeval50_to_timeval(const struct timeval50 * ts50,struct timeval * ts)68 static __inline void timeval50_to_timeval(const struct timeval50 *ts50,
69 struct timeval *ts)
70 {
71 ts->tv_sec = ts50->tv_sec;
72 ts->tv_usec = (suseconds_t)ts50->tv_usec;
73 }
74
timeval_to_timeval50(const struct timeval * ts,struct timeval50 * ts50)75 static __inline void timeval_to_timeval50(const struct timeval *ts,
76 struct timeval50 *ts50)
77 {
78 ts50->tv_sec = (long)ts->tv_sec;
79 ts50->tv_usec = ts->tv_usec;
80 }
81
timespec50_to_timespec(const struct timespec50 * ts50,struct timespec * ts)82 static __inline void timespec50_to_timespec(const struct timespec50 *ts50,
83 struct timespec *ts)
84 {
85 ts->tv_sec = ts50->tv_sec;
86 ts->tv_nsec = ts50->tv_nsec;
87 }
88
timespec_to_timespec50(const struct timespec * ts,struct timespec50 * ts50)89 static __inline void timespec_to_timespec50(const struct timespec *ts,
90 struct timespec50 *ts50)
91 {
92 ts50->tv_sec = (int32_t)ts->tv_sec;
93 ts50->tv_nsec = ts->tv_nsec;
94 }
95
itimerval50_to_itimerval(const struct itimerval50 * ts50,struct itimerval * ts)96 static __inline void itimerval50_to_itimerval(const struct itimerval50 *ts50,
97 struct itimerval *ts)
98 {
99 timeval50_to_timeval(&ts50->it_interval, &ts->it_interval);
100 timeval50_to_timeval(&ts50->it_value, &ts->it_value);
101 }
102
itimerval_to_itimerval50(const struct itimerval * ts,struct itimerval50 * ts50)103 static __inline void itimerval_to_itimerval50(const struct itimerval *ts,
104 struct itimerval50 *ts50)
105 {
106 timeval_to_timeval50(&ts->it_interval, &ts50->it_interval);
107 timeval_to_timeval50(&ts->it_value, &ts50->it_value);
108 }
109
itimerspec50_to_itimerspec(const struct itimerspec50 * ts50,struct itimerspec * ts)110 static __inline void itimerspec50_to_itimerspec(const struct itimerspec50 *ts50,
111 struct itimerspec *ts)
112 {
113 timespec50_to_timespec(&ts50->it_interval, &ts->it_interval);
114 timespec50_to_timespec(&ts50->it_value, &ts->it_value);
115 }
116
itimerspec_to_itimerspec50(const struct itimerspec * ts,struct itimerspec50 * ts50)117 static __inline void itimerspec_to_itimerspec50(const struct itimerspec *ts,
118 struct itimerspec50 *ts50)
119 {
120 timespec_to_timespec50(&ts->it_interval, &ts50->it_interval);
121 timespec_to_timespec50(&ts->it_value, &ts50->it_value);
122 }
123
124 #endif /* _COMPAT_SYS_TIME_TYPES_H_ */
125