1570af302Sopenharmony_ci#include "time32.h"
2570af302Sopenharmony_ci#include <time.h>
3570af302Sopenharmony_ci
4570af302Sopenharmony_ciint __timer_settime32(timer_t t, int flags, const struct itimerspec32 *restrict val32, struct itimerspec32 *restrict old32)
5570af302Sopenharmony_ci{
6570af302Sopenharmony_ci	struct itimerspec old;
7570af302Sopenharmony_ci	int r = timer_settime(t, flags, (&(struct itimerspec){
8570af302Sopenharmony_ci		.it_interval.tv_sec = val32->it_interval.tv_sec,
9570af302Sopenharmony_ci		.it_interval.tv_nsec = val32->it_interval.tv_nsec,
10570af302Sopenharmony_ci		.it_value.tv_sec = val32->it_value.tv_sec,
11570af302Sopenharmony_ci		.it_value.tv_nsec = val32->it_value.tv_nsec}),
12570af302Sopenharmony_ci		old32 ? &old : 0);
13570af302Sopenharmony_ci	if (r) return r;
14570af302Sopenharmony_ci	/* The above call has already committed to success by changing the
15570af302Sopenharmony_ci	 * timer setting, so we can't fail on out-of-range old value.
16570af302Sopenharmony_ci	 * Since these are relative times, values large enough to overflow
17570af302Sopenharmony_ci	 * don't make sense anyway. */
18570af302Sopenharmony_ci	if (old32) {
19570af302Sopenharmony_ci		old32->it_interval.tv_sec = old.it_interval.tv_sec;
20570af302Sopenharmony_ci		old32->it_interval.tv_nsec = old.it_interval.tv_nsec;
21570af302Sopenharmony_ci		old32->it_value.tv_sec = old.it_value.tv_sec;
22570af302Sopenharmony_ci		old32->it_value.tv_nsec = old.it_value.tv_nsec;
23570af302Sopenharmony_ci	}
24570af302Sopenharmony_ci	return 0;
25570af302Sopenharmony_ci}
26