1 /* $NetBSD: time_types.h,v 1.6 2021/09/07 11:43:05 riastradh 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 #ifdef _KERNEL
38 #include <lib/libkern/libkern.h>
39 #else
40 #include <stddef.h>
41 #include <string.h>
42 #endif
43
44 /*
45 * Structure returned by gettimeofday(2) system call,
46 * and used in other calls.
47 */
48 struct timeval50 {
49 long tv_sec; /* seconds */
50 long tv_usec; /* and microseconds */
51 };
52
53 struct itimerval50 {
54 struct timeval50 it_interval; /* timer interval */
55 struct timeval50 it_value; /* current value */
56 };
57
58 /*
59 * Structure defined by POSIX.1b to be like a timeval.
60 */
61 struct timespec50 {
62 int32_t tv_sec; /* seconds */
63 long tv_nsec; /* and nanoseconds */
64 };
65
66 /*
67 * Structure defined by POSIX.1b to be like a itimerval, but with
68 * timespecs. Used in the timer_*() system calls.
69 */
70 struct itimerspec50 {
71 struct timespec50 it_interval;
72 struct timespec50 it_value;
73 };
74
75 static __inline void
timeval50_to_timeval(const struct timeval50 * ts50,struct timeval * ts)76 timeval50_to_timeval(const struct timeval50 *ts50, struct timeval *ts)
77 {
78 memset(ts, 0, sizeof(*ts));
79 ts->tv_sec = ts50->tv_sec;
80 ts->tv_usec = (suseconds_t)ts50->tv_usec;
81 }
82
83 static __inline void
timeval_to_timeval50(const struct timeval * ts,struct timeval50 * ts50)84 timeval_to_timeval50(const struct timeval *ts, struct timeval50 *ts50)
85 {
86 memset(ts50, 0, sizeof(*ts50));
87 ts50->tv_sec = (long)ts->tv_sec;
88 ts50->tv_usec = ts->tv_usec;
89 }
90
91 static __inline void
timespec50_to_timespec(const struct timespec50 * ts50,struct timespec * ts)92 timespec50_to_timespec(const struct timespec50 *ts50, struct timespec *ts)
93 {
94 memset(ts, 0, sizeof(*ts));
95 ts->tv_sec = ts50->tv_sec;
96 ts->tv_nsec = ts50->tv_nsec;
97 }
98
99 static __inline void
timespec_to_timespec50(const struct timespec * ts,struct timespec50 * ts50)100 timespec_to_timespec50(const struct timespec *ts, struct timespec50 *ts50)
101 {
102 memset(ts50, 0, sizeof(*ts50));
103 ts50->tv_sec = (int32_t)ts->tv_sec;
104 ts50->tv_nsec = ts->tv_nsec;
105 }
106
107 static __inline void
itimerval50_to_itimerval(const struct itimerval50 * ts50,struct itimerval * ts)108 itimerval50_to_itimerval(const struct itimerval50 *ts50, struct itimerval *ts)
109 {
110 memset(ts, 0, sizeof(*ts));
111 timeval50_to_timeval(&ts50->it_interval, &ts->it_interval);
112 timeval50_to_timeval(&ts50->it_value, &ts->it_value);
113 }
114
115 static __inline void
itimerval_to_itimerval50(const struct itimerval * ts,struct itimerval50 * ts50)116 itimerval_to_itimerval50(const struct itimerval *ts, struct itimerval50 *ts50)
117 {
118 memset(ts50, 0, sizeof(*ts50));
119 timeval_to_timeval50(&ts->it_interval, &ts50->it_interval);
120 timeval_to_timeval50(&ts->it_value, &ts50->it_value);
121 }
122
123 static __inline void
itimerspec50_to_itimerspec(const struct itimerspec50 * ts50,struct itimerspec * ts)124 itimerspec50_to_itimerspec(const struct itimerspec50 *ts50,
125 struct itimerspec *ts)
126 {
127 memset(ts, 0, sizeof(*ts));
128 timespec50_to_timespec(&ts50->it_interval, &ts->it_interval);
129 timespec50_to_timespec(&ts50->it_value, &ts->it_value);
130 }
131
132 static __inline void
itimerspec_to_itimerspec50(const struct itimerspec * ts,struct itimerspec50 * ts50)133 itimerspec_to_itimerspec50(const struct itimerspec *ts,
134 struct itimerspec50 *ts50)
135 {
136 memset(ts50, 0, sizeof(*ts50));
137 timespec_to_timespec50(&ts->it_interval, &ts50->it_interval);
138 timespec_to_timespec50(&ts->it_value, &ts50->it_value);
139 }
140
141 #endif /* _COMPAT_SYS_TIME_TYPES_H_ */
142