1570af302Sopenharmony_ci#include "time32.h"
2570af302Sopenharmony_ci#include <time.h>
3570af302Sopenharmony_ci#include <sys/time.h>
4570af302Sopenharmony_ci#include <sys/timex.h>
5570af302Sopenharmony_ci#include <string.h>
6570af302Sopenharmony_ci#include <stddef.h>
7570af302Sopenharmony_ci
8570af302Sopenharmony_cistruct timex32 {
9570af302Sopenharmony_ci	unsigned modes;
10570af302Sopenharmony_ci	long offset, freq, maxerror, esterror;
11570af302Sopenharmony_ci	int status;
12570af302Sopenharmony_ci	long constant, precision, tolerance;
13570af302Sopenharmony_ci	struct timeval32 time;
14570af302Sopenharmony_ci	long tick, ppsfreq, jitter;
15570af302Sopenharmony_ci	int shift;
16570af302Sopenharmony_ci	long stabil, jitcnt, calcnt, errcnt, stbcnt;
17570af302Sopenharmony_ci	int tai;
18570af302Sopenharmony_ci	int __padding[11];
19570af302Sopenharmony_ci};
20570af302Sopenharmony_ci
21570af302Sopenharmony_ciint __clock_adjtime32(clockid_t clock_id, struct timex32 *tx32)
22570af302Sopenharmony_ci{
23570af302Sopenharmony_ci	struct timex utx = {
24570af302Sopenharmony_ci		.modes = tx32->modes,
25570af302Sopenharmony_ci		.offset = tx32->offset,
26570af302Sopenharmony_ci		.freq = tx32->freq,
27570af302Sopenharmony_ci		.maxerror = tx32->maxerror,
28570af302Sopenharmony_ci		.esterror = tx32->esterror,
29570af302Sopenharmony_ci		.status = tx32->status,
30570af302Sopenharmony_ci		.constant = tx32->constant,
31570af302Sopenharmony_ci		.precision = tx32->precision,
32570af302Sopenharmony_ci		.tolerance = tx32->tolerance,
33570af302Sopenharmony_ci		.time.tv_sec = tx32->time.tv_sec,
34570af302Sopenharmony_ci		.time.tv_usec = tx32->time.tv_usec,
35570af302Sopenharmony_ci		.tick = tx32->tick,
36570af302Sopenharmony_ci		.ppsfreq = tx32->ppsfreq,
37570af302Sopenharmony_ci		.jitter = tx32->jitter,
38570af302Sopenharmony_ci		.shift = tx32->shift,
39570af302Sopenharmony_ci		.stabil = tx32->stabil,
40570af302Sopenharmony_ci		.jitcnt = tx32->jitcnt,
41570af302Sopenharmony_ci		.calcnt = tx32->calcnt,
42570af302Sopenharmony_ci		.errcnt = tx32->errcnt,
43570af302Sopenharmony_ci		.stbcnt = tx32->stbcnt,
44570af302Sopenharmony_ci		.tai = tx32->tai,
45570af302Sopenharmony_ci	};
46570af302Sopenharmony_ci	int r = clock_adjtime(clock_id, &utx);
47570af302Sopenharmony_ci	if (r<0) return r;
48570af302Sopenharmony_ci	tx32->modes = utx.modes;
49570af302Sopenharmony_ci	tx32->offset = utx.offset;
50570af302Sopenharmony_ci	tx32->freq = utx.freq;
51570af302Sopenharmony_ci	tx32->maxerror = utx.maxerror;
52570af302Sopenharmony_ci	tx32->esterror = utx.esterror;
53570af302Sopenharmony_ci	tx32->status = utx.status;
54570af302Sopenharmony_ci	tx32->constant = utx.constant;
55570af302Sopenharmony_ci	tx32->precision = utx.precision;
56570af302Sopenharmony_ci	tx32->tolerance = utx.tolerance;
57570af302Sopenharmony_ci	tx32->time.tv_sec = utx.time.tv_sec;
58570af302Sopenharmony_ci	tx32->time.tv_usec = utx.time.tv_usec;
59570af302Sopenharmony_ci	tx32->tick = utx.tick;
60570af302Sopenharmony_ci	tx32->ppsfreq = utx.ppsfreq;
61570af302Sopenharmony_ci	tx32->jitter = utx.jitter;
62570af302Sopenharmony_ci	tx32->shift = utx.shift;
63570af302Sopenharmony_ci	tx32->stabil = utx.stabil;
64570af302Sopenharmony_ci	tx32->jitcnt = utx.jitcnt;
65570af302Sopenharmony_ci	tx32->calcnt = utx.calcnt;
66570af302Sopenharmony_ci	tx32->errcnt = utx.errcnt;
67570af302Sopenharmony_ci	tx32->stbcnt = utx.stbcnt;
68570af302Sopenharmony_ci	tx32->tai = utx.tai;
69570af302Sopenharmony_ci	return r;
70570af302Sopenharmony_ci}
71