2.9
[glibc/nacl-glibc.git] / sysdeps / unix / sysv / linux / alpha / adjtime.c
blob1700524d34a91963d1bcd41189f005030212a913
1 /* Copyright (C) 1998,2000,2002,2003,2004,2006 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
19 #include <shlib-compat.h>
20 #include <sysdep.h>
21 #include <sys/time.h>
22 #include <kernel-features.h>
24 #if !defined __ASSUME_TIMEVAL64 || SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
25 struct timeval32
27 int tv_sec, tv_usec;
30 struct timex32 {
31 unsigned int modes; /* mode selector */
32 long offset; /* time offset (usec) */
33 long freq; /* frequency offset (scaled ppm) */
34 long maxerror; /* maximum error (usec) */
35 long esterror; /* estimated error (usec) */
36 int status; /* clock command/status */
37 long constant; /* pll time constant */
38 long precision; /* clock precision (usec) (read only) */
39 long tolerance; /* clock frequency tolerance (ppm)
40 * (read only)
42 struct timeval32 time; /* (read only) */
43 long tick; /* (modified) usecs between clock ticks */
45 long ppsfreq; /* pps frequency (scaled ppm) (ro) */
46 long jitter; /* pps jitter (us) (ro) */
47 int shift; /* interval duration (s) (shift) (ro) */
48 long stabil; /* pps stability (scaled ppm) (ro) */
49 long jitcnt; /* jitter limit exceeded (ro) */
50 long calcnt; /* calibration intervals (ro) */
51 long errcnt; /* calibration errors (ro) */
52 long stbcnt; /* stability limit exceeded (ro) */
54 int :32; int :32; int :32; int :32;
55 int :32; int :32; int :32; int :32;
56 int :32; int :32; int :32; int :32;
59 #define TIMEVAL timeval32
60 #define TIMEX timex32
61 #define ADJTIME attribute_compat_text_section __adjtime_tv32
62 #define ADJTIMEX(x) INLINE_SYSCALL (old_adjtimex, 1, x)
63 #define ADJTIMEX32(x) INLINE_SYSCALL (old_adjtimex, 1, x)
64 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
65 #define LINKAGE
66 #else
67 #define LINKAGE static
68 #endif
70 LINKAGE int ADJTIME (const struct TIMEVAL *itv, struct TIMEVAL *otv);
72 #include <sysdeps/unix/sysv/linux/adjtime.c>
74 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
75 int
76 attribute_compat_text_section
77 __adjtimex_tv32 (struct timex32 *tx) { return ADJTIMEX (tx); }
78 strong_alias (__adjtimex_tv32, __adjtimex_tv32_1);
79 strong_alias (__adjtimex_tv32, __adjtimex_tv32_2);
80 compat_symbol (libc, __adjtimex_tv32_1, __adjtimex, GLIBC_2_0);
81 compat_symbol (libc, __adjtimex_tv32_2, adjtimex, GLIBC_2_0);
82 compat_symbol (libc, __adjtime_tv32, adjtime, GLIBC_2_0);
83 #endif
84 #endif /* !__ASSUME_TIMEVAL64 || SHLIB_COMPAT */
86 #undef TIMEVAL
87 #define TIMEVAL timeval
88 #undef TIMEX
89 #define TIMEX timex
90 #undef ADJTIMEX
91 #define ADJTIMEX(x) INLINE_SYSCALL (adjtimex, 1, x)
93 #undef LINKAGE
94 #undef ADJTIME
95 #if !defined __ASSUME_TIMEVAL64
96 #define LINKAGE static
97 #define ADJTIME __adjtime_tv64
98 #endif
100 #include <sysdeps/unix/sysv/linux/adjtime.c>
101 #include <stdbool.h>
103 #if !defined __ASSUME_TIMEVAL64
104 static bool missing_adjtimex;
107 __adjtime (itv, otv)
108 const struct timeval *itv;
109 struct timeval *otv;
111 struct timeval32 itv32, otv32;
112 int ret;
114 switch (missing_adjtimex)
116 case false:
117 ret = __adjtime_tv64 (itv, otv);
118 if (ret && errno == ENOSYS)
119 missing_adjtimex = 1;
120 else
121 break;
123 /* FALLTHRU */
125 default:
126 itv32.tv_sec = itv->tv_sec;
127 itv32.tv_usec = itv->tv_usec;
128 ret = __adjtime_tv32 (&itv32, &otv32);
129 if (ret == 0)
131 otv->tv_sec = otv32.tv_sec;
132 otv->tv_usec = otv32.tv_usec;
134 break;
137 return ret;
139 #endif
141 versioned_symbol (libc, __adjtime, adjtime, GLIBC_2_1);
144 __adjtimex_tv64 (struct timex *tx)
146 #if defined __ASSUME_TIMEVAL64
147 return ADJTIMEX (tx);
148 #else
149 struct timex32 tx32;
150 int ret;
152 switch (missing_adjtimex)
154 case false:
155 ret = ADJTIMEX (tx);
156 if (ret && errno == ENOSYS)
157 missing_adjtimex = 1;
158 else
159 break;
161 /* FALLTHRU */
163 default:
164 tx32.modes = tx->modes;
165 tx32.offset = tx->offset;
166 tx32.freq = tx->freq;
167 tx32.maxerror = tx->maxerror;
168 tx32.esterror = tx->esterror;
169 tx32.status = tx->status;
170 tx32.constant = tx->constant;
171 tx32.precision = tx->precision;
172 tx32.tolerance = tx->tolerance;
173 tx32.time.tv_sec = tx->time.tv_sec;
174 tx32.time.tv_sec = tx->time.tv_usec;
175 tx32.tick = tx->tick;
176 tx32.ppsfreq = tx->ppsfreq;
177 tx32.jitter = tx->jitter;
178 tx32.shift = tx->shift;
179 tx32.stabil = tx->stabil;
180 tx32.jitcnt = tx->jitcnt;
181 tx32.calcnt = tx->calcnt;
182 tx32.errcnt = tx->errcnt;
183 tx32.stbcnt = tx->stbcnt;
185 ret = ADJTIMEX32 (&tx32);
186 if (ret == 0)
188 tx->modes = tx32.modes;
189 tx->offset = tx32.offset;
190 tx->freq = tx32.freq;
191 tx->maxerror = tx32.maxerror;
192 tx->esterror = tx32.esterror;
193 tx->status = tx32.status;
194 tx->constant = tx32.constant;
195 tx->precision = tx32.precision;
196 tx->tolerance = tx32.tolerance;
197 tx->time.tv_sec = tx32.time.tv_sec;
198 tx->time.tv_usec = tx32.time.tv_sec;
199 tx->tick = tx32.tick;
200 tx->ppsfreq = tx32.ppsfreq;
201 tx->jitter = tx32.jitter;
202 tx->shift = tx32.shift;
203 tx->stabil = tx32.stabil;
204 tx->jitcnt = tx32.jitcnt;
205 tx->calcnt = tx32.calcnt;
206 tx->errcnt = tx32.errcnt;
207 tx->stbcnt = tx32.stbcnt;
209 break;
212 return ret;
213 #endif
216 strong_alias (__adjtimex_tv64, __adjtimex_internal);
217 strong_alias (__adjtimex_tv64, __adjtimex_tv64p);
218 weak_alias (__adjtimex_tv64, ntp_adjtime);
219 versioned_symbol (libc, __adjtimex_tv64, __adjtimex, GLIBC_2_1);
220 versioned_symbol (libc, __adjtimex_tv64p, adjtimex, GLIBC_2_1);