| 1 | /* Internal declarations for sys/timex.h. |
|---|---|
| 2 | Copyright (C) 2014-2020 Free Software Foundation, Inc. |
| 3 | This file is part of the GNU C Library. |
| 4 | |
| 5 | The GNU C Library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | The GNU C Library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with the GNU C Library; if not, see |
| 17 | <https://www.gnu.org/licenses/>. */ |
| 18 | |
| 19 | #ifndef _INCLUDE_SYS_TIMEX_H |
| 20 | #define _INCLUDE_SYS_TIMEX_H 1 |
| 21 | |
| 22 | #include_next <sys/timex.h> |
| 23 | |
| 24 | # ifndef _ISOMAC |
| 25 | |
| 26 | libc_hidden_proto (__adjtimex) |
| 27 | |
| 28 | # include <time.h> |
| 29 | # include <struct___timeval64.h> |
| 30 | /* Local definition of 64 bit time supporting timex struct */ |
| 31 | # if __TIMESIZE == 64 |
| 32 | # define __timex64 timex |
| 33 | # define __clock_adjtime64 __clock_adjtime |
| 34 | # define ___adjtimex64 ___adjtimex |
| 35 | # define __ntptimeval64 ntptimeval |
| 36 | # define __ntp_gettime64 __ntp_gettime |
| 37 | # define __ntp_gettimex64 __ntp_gettimex |
| 38 | # else |
| 39 | |
| 40 | struct __timex64 |
| 41 | { |
| 42 | unsigned int modes; /* mode selector */ |
| 43 | int :32; /* pad */ |
| 44 | long long int offset; /* time offset (usec) */ |
| 45 | long long int freq; /* frequency offset (scaled ppm) */ |
| 46 | long long int maxerror; /* maximum error (usec) */ |
| 47 | long long int esterror; /* estimated error (usec) */ |
| 48 | int status; /* clock command/status */ |
| 49 | int :32; /* pad */ |
| 50 | long long int constant; /* pll time constant */ |
| 51 | long long int precision; /* clock precision (usec) (read only) */ |
| 52 | long long int tolerance; /* clock frequency tolerance (ppm) (ro) */ |
| 53 | struct __timeval64 time; /* (read only, except for ADJ_SETOFFSET) */ |
| 54 | long long int tick; /* (modified) usecs between clock ticks */ |
| 55 | long long int ppsfreq; /* pps frequency (scaled ppm) (ro) */ |
| 56 | long long int jitter; /* pps jitter (us) (ro) */ |
| 57 | int shift; /* interval duration (s) (shift) (ro) */ |
| 58 | int :32; /* pad */ |
| 59 | long long int stabil; /* pps stability (scaled ppm) (ro) */ |
| 60 | long long int jitcnt; /* jitter limit exceeded (ro) */ |
| 61 | long long int calcnt; /* calibration intervals (ro) */ |
| 62 | long long int errcnt; /* calibration errors (ro) */ |
| 63 | long long int stbcnt; /* stability limit exceeded (ro) */ |
| 64 | |
| 65 | int tai; /* TAI offset (ro) */ |
| 66 | |
| 67 | int :32; |
| 68 | int :32; |
| 69 | int :32; |
| 70 | int :32; |
| 71 | int :32; |
| 72 | int :32; |
| 73 | int :32; |
| 74 | int :32; |
| 75 | int :32; |
| 76 | int :32; |
| 77 | int :32; |
| 78 | }; |
| 79 | extern int __clock_adjtime64 (const clockid_t clock_id, struct __timex64 *tx64); |
| 80 | libc_hidden_proto (__clock_adjtime64); |
| 81 | extern int ___adjtimex64 (struct __timex64 *tx64); |
| 82 | libc_hidden_proto (___adjtimex64) |
| 83 | |
| 84 | struct __ntptimeval64 |
| 85 | { |
| 86 | struct __timeval64 time; /* current time (ro) */ |
| 87 | long int maxerror; /* maximum error (us) (ro) */ |
| 88 | long int esterror; /* estimated error (us) (ro) */ |
| 89 | long int tai; /* TAI offset (ro) */ |
| 90 | |
| 91 | long int __glibc_reserved1; |
| 92 | long int __glibc_reserved2; |
| 93 | long int __glibc_reserved3; |
| 94 | long int __glibc_reserved4; |
| 95 | }; |
| 96 | extern int __ntp_gettime64 (struct __ntptimeval64 *ntv); |
| 97 | libc_hidden_proto (__ntp_gettime64) |
| 98 | extern int __ntp_gettimex64 (struct __ntptimeval64 *ntv); |
| 99 | libc_hidden_proto (__ntp_gettimex64) |
| 100 | |
| 101 | # endif |
| 102 | |
| 103 | /* Convert a known valid struct timex into a struct __timex64. */ |
| 104 | static inline struct __timex64 |
| 105 | valid_timex_to_timex64 (const struct timex tx) |
| 106 | { |
| 107 | struct __timex64 tx64; |
| 108 | |
| 109 | tx64.modes = tx.modes; |
| 110 | tx64.offset = tx.offset; |
| 111 | tx64.freq = tx.freq; |
| 112 | tx64.maxerror = tx.maxerror; |
| 113 | tx64.esterror = tx.esterror; |
| 114 | tx64.status = tx.status; |
| 115 | tx64.constant = tx.constant; |
| 116 | tx64.precision = tx.precision; |
| 117 | tx64.tolerance = tx.tolerance; |
| 118 | tx64.time = valid_timeval_to_timeval64 (tx.time); |
| 119 | tx64.tick = tx.tick; |
| 120 | tx64.ppsfreq = tx.ppsfreq; |
| 121 | tx64.jitter = tx.jitter; |
| 122 | tx64.shift = tx.shift; |
| 123 | tx64.stabil = tx.stabil; |
| 124 | tx64.jitcnt = tx.jitcnt; |
| 125 | tx64.calcnt = tx.calcnt; |
| 126 | tx64.errcnt = tx.errcnt; |
| 127 | tx64.stbcnt = tx.stbcnt; |
| 128 | tx64.tai = tx.tai; |
| 129 | |
| 130 | return tx64; |
| 131 | } |
| 132 | |
| 133 | /* Convert a known valid struct __timex64 into a struct timex. */ |
| 134 | static inline struct timex |
| 135 | valid_timex64_to_timex (const struct __timex64 tx64) |
| 136 | { |
| 137 | struct timex tx; |
| 138 | |
| 139 | tx.modes = tx64.modes; |
| 140 | tx.offset = tx64.offset; |
| 141 | tx.freq = tx64.freq; |
| 142 | tx.maxerror = tx64.maxerror; |
| 143 | tx.esterror = tx64.esterror; |
| 144 | tx.status = tx64.status; |
| 145 | tx.constant = tx64.constant; |
| 146 | tx.precision = tx64.precision; |
| 147 | tx.tolerance = tx64.tolerance; |
| 148 | tx.time = valid_timeval64_to_timeval (tx64.time); |
| 149 | tx.tick = tx64.tick; |
| 150 | tx.ppsfreq = tx64.ppsfreq; |
| 151 | tx.jitter = tx64.jitter; |
| 152 | tx.shift = tx64.shift; |
| 153 | tx.stabil = tx64.stabil; |
| 154 | tx.jitcnt = tx64.jitcnt; |
| 155 | tx.calcnt = tx64.calcnt; |
| 156 | tx.errcnt = tx64.errcnt; |
| 157 | tx.stbcnt = tx64.stbcnt; |
| 158 | tx.tai = tx64.tai; |
| 159 | |
| 160 | return tx; |
| 161 | } |
| 162 | |
| 163 | /* Convert a known valid struct ntptimeval into a struct __ntptimeval64. */ |
| 164 | static inline struct __ntptimeval64 |
| 165 | valid_ntptimeval_to_ntptimeval64 (const struct ntptimeval ntv) |
| 166 | { |
| 167 | struct __ntptimeval64 ntv64; |
| 168 | |
| 169 | ntv64.time = valid_timeval_to_timeval64 (ntv.time); |
| 170 | ntv64.maxerror = ntv.maxerror; |
| 171 | ntv64.esterror = ntv.esterror; |
| 172 | ntv64.tai = ntv.tai; |
| 173 | ntv64.__glibc_reserved1 = 0; |
| 174 | ntv64.__glibc_reserved2 = 0; |
| 175 | ntv64.__glibc_reserved3 = 0; |
| 176 | ntv64.__glibc_reserved4 = 0; |
| 177 | |
| 178 | return ntv64; |
| 179 | } |
| 180 | |
| 181 | /* Convert a known valid struct __ntptimeval64 into a struct ntptimeval. */ |
| 182 | static inline struct ntptimeval |
| 183 | valid_ntptimeval64_to_ntptimeval (const struct __ntptimeval64 ntp64) |
| 184 | { |
| 185 | struct ntptimeval ntp; |
| 186 | |
| 187 | ntp.time = valid_timeval64_to_timeval (ntp64.time); |
| 188 | ntp.maxerror = ntp64.maxerror; |
| 189 | ntp.esterror = ntp64.esterror; |
| 190 | ntp.tai = ntp64.tai; |
| 191 | ntp.__glibc_reserved1 = 0; |
| 192 | ntp.__glibc_reserved2 = 0; |
| 193 | ntp.__glibc_reserved3 = 0; |
| 194 | ntp.__glibc_reserved4 = 0; |
| 195 | |
| 196 | return ntp; |
| 197 | } |
| 198 | # endif /* _ISOMAC */ |
| 199 | #endif /* sys/timex.h */ |
| 200 |