1 /*
2  * Copyright (c) 1982, 1986 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *    This product includes software developed by the University of
16  *    California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS `AS IS' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  *    @(#)time.h    7.6 (Berkeley) 2/22/91
34  */
35 
36 /* messed about with substantially by @feilipu October 2019 */
37 
38 
39 // automatically generated by m4 from headers in proto subdir
40 
41 
42 #ifndef _SYS_TIME_H_
43 #define _SYS_TIME_H_
44 
45 #include <sys/types.h>
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 /*
52  * Structure returned by clock_gettime() system call
53  * and used in other calls.
54  */
55 
56 struct timespec {
57     time_t      tv_sec;     /* seconds */
58     nseconds_t  tv_nsec;    /* and nanoseconds */
59 };
60 
61 enum clockid_t {
62     CLOCK_REALTIME,
63     CLOCK_MONOTONIC,
64     CLOCK_PROCESS_CPUTIME_ID,
65     CLOCK_THREAD_CPUTIME_ID,
66     CLOCK_MONOTONIC_RAW,
67     CLOCK_REALTIME_COARSE,
68     CLOCK_MONOTONIC_COARSE
69 };
70 
71 /*
72  * Convenience macros for operations on timevals
73  */
74 
75 #define    timerisset(tvp)  ((tvp)->tv_sec || (tvp)->tv_nsec)
76 #define    timerclear(tvp)  ((tvp)->tv_sec = (tvp)->tv_nsec = 0)
77 
78 #define    timeradd(a, b, result)                               \
79   do {                                                          \
80     (result)->tv_sec = (a)->tv_sec + (b)->tv_sec;               \
81     (result)->tv_nsec = (a)->tv_nsec + (b)->tv_nsec;            \
82     if ((result)->tv_nsec >= 1000000000)                        \
83       {                                                         \
84         ++(result)->tv_sec;                                     \
85         (result)->tv_nsec -= 1000000000;                        \
86       }                                                         \
87   } while (0)
88 
89 #define    timersub(a, b, result)                               \
90   do {                                                          \
91     (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;               \
92     (result)->tv_nsec = (a)->tv_nsec - (b)->tv_nsec;            \
93     if ((a)->tv_nsec < (b)->tv_nsec)                            \
94       {                                                         \
95         --(result)->tv_sec;                                     \
96         (result)->tv_nsec += 1000000000;                        \
97       }                                                         \
98   } while (0)
99 
100 /*
101  * We are working in nano seconds, so divide by ONE_BILLION
102  */
103 
104 #ifndef ONE_BILLION
105 #define ONE_BILLION     ((nseconds_t)1000000000)
106 #endif
107 
108 extern int __LIB__ clock_getres(enum clockid_t clock_id,struct timespec *res) __smallc;
109 extern int __LIB__ clock_getres_callee(enum clockid_t clock_id,struct timespec *res) __smallc __z88dk_callee;
110 #define clock_getres(a,b) clock_getres_callee(a,b)
111 
112 
113 extern int __LIB__ clock_gettime(enum clockid_t clock_id,struct timespec *tp) __smallc;
114 extern int __LIB__ clock_gettime_callee(enum clockid_t clock_id,struct timespec *tp) __smallc __z88dk_callee;
115 #define clock_gettime(a,b) clock_gettime_callee(a,b)
116 
117 
118 extern int __LIB__ clock_settime(enum clockid_t clock_id,const struct timespec *tp) __smallc;
119 extern int __LIB__ clock_settime_callee(enum clockid_t clock_id,const struct timespec *tp) __smallc __z88dk_callee;
120 #define clock_settime(a,b) clock_settime_callee(a,b)
121 
122 
123 
124 #ifdef __cplusplus
125 }
126 #endif
127 #endif /* !_SYS_TIME_H_ */
128