chiark / gitweb /
eglibc (2.11.3-4+deb6u3) squeeze-lts; urgency=medium
[eglibc.git] / ports / sysdeps / unix / sysv / linux / alpha / adjtime.c
1 /* Copyright (C) 1998,2000,2002,2003,2004,2006 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3
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.
8
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.
13
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.  */
18
19 #include <shlib-compat.h>
20 #include <sysdep.h>
21 #include <sys/time.h>
22 #include <kernel-features.h>
23
24 #if !defined __ASSUME_TIMEVAL64 || SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
25 struct timeval32
26 {
27     int tv_sec, tv_usec;
28 };
29
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)
41                                  */
42         struct timeval32 time;  /* (read only) */
43         long tick;              /* (modified) usecs between clock ticks */
44
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) */
53
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;
57 };
58
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
69
70 LINKAGE int ADJTIME (const struct TIMEVAL *itv, struct TIMEVAL *otv);
71
72 #include <sysdeps/unix/sysv/linux/adjtime.c>
73
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 */
85
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)
92
93 #undef LINKAGE
94 #undef ADJTIME
95 #if !defined __ASSUME_TIMEVAL64
96 #define LINKAGE         static
97 #define ADJTIME         __adjtime_tv64
98 #endif
99
100 #include <sysdeps/unix/sysv/linux/adjtime.c>
101 #include <stdbool.h>
102
103 #if !defined __ASSUME_TIMEVAL64
104 static bool missing_adjtimex;
105
106 int
107 __adjtime (itv, otv)
108      const struct timeval *itv;
109      struct timeval *otv;
110 {
111   struct timeval32 itv32, otv32;
112   int ret;
113
114   switch (missing_adjtimex)
115     {
116     case false:
117       ret = __adjtime_tv64 (itv, otv);
118       if (ret && errno == ENOSYS)
119         missing_adjtimex = 1;
120       else
121         break;
122
123       /* FALLTHRU */
124
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)
130         {
131           otv->tv_sec = otv32.tv_sec;
132           otv->tv_usec = otv32.tv_usec;
133         }
134       break;
135     }
136
137   return ret;
138 }
139 #endif
140
141 versioned_symbol (libc, __adjtime, adjtime, GLIBC_2_1);
142
143 int
144 __adjtimex_tv64 (struct timex *tx)
145 {
146 #if defined __ASSUME_TIMEVAL64
147   return ADJTIMEX (tx);
148 #else
149   struct timex32 tx32;
150   int ret;
151
152   switch (missing_adjtimex)
153     {
154     case false:
155       ret = ADJTIMEX (tx);
156       if (ret && errno == ENOSYS)
157         missing_adjtimex = 1;
158       else
159         break;
160
161       /* FALLTHRU */
162
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;
184
185       ret = ADJTIMEX32 (&tx32);
186       if (ret == 0)
187         {
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;
208         }
209       break;
210     }
211
212   return ret;
213 #endif
214 }
215
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);