summaryrefslogtreecommitdiff
path: root/compat/time32/timer_settime32.c
blob: a447e7d41aa79081b106e396e52822923d85d334 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "time32.h"
#include <time.h>

int __timer_settime32(timer_t t, int flags, const struct itimerspec32 *restrict val32, struct itimerspec32 *restrict old32)
{
	struct itimerspec old;
	int r = timer_settime(t, flags, (&(struct itimerspec){
		.it_interval.tv_sec = val32->it_interval.tv_sec,
		.it_interval.tv_nsec = val32->it_interval.tv_nsec,
		.it_value.tv_sec = val32->it_value.tv_sec,
		.it_value.tv_nsec = val32->it_value.tv_nsec}),
		old32 ? &old : 0);
	if (r) return r;
	/* The above call has already committed to success by changing the
	 * timer setting, so we can't fail on out-of-range old value.
	 * Since these are relative times, values large enough to overflow
	 * don't make sense anyway. */
	if (old32) {
		old32->it_interval.tv_sec = old.it_interval.tv_sec;
		old32->it_interval.tv_nsec = old.it_interval.tv_nsec;
		old32->it_value.tv_sec = old.it_value.tv_sec;
		old32->it_value.tv_nsec = old.it_value.tv_nsec;
	}
	return 0;
}