| 1 | #include "time32.h" |
| 2 | #include <time.h> |
| 3 | #include <sys/time.h> |
| 4 | |
| 5 | int __setitimer_time32(int which, const struct itimerval32 *restrict new32, struct itimerval32 *restrict old32) |
| 6 | { |
| 7 | 	struct itimerval old; |
| 8 | 	int r = setitimer(which, (&(struct itimerval){ |
| 9 | 		.it_interval.tv_sec = new32->it_interval.tv_sec, |
| 10 | 		.it_interval.tv_usec = new32->it_interval.tv_usec, |
| 11 | 		.it_value.tv_sec = new32->it_value.tv_sec, |
| 12 | 		.it_value.tv_usec = new32->it_value.tv_usec}), &old); |
| 13 | 	if (r) return r; |
| 14 | 	/* The above call has already committed to success by changing the |
| 15 | 	 * timer setting, so we can't fail on out-of-range old value. |
| 16 | 	 * Since these are relative times, values large enough to overflow |
| 17 | 	 * don't make sense anyway. */ |
| 18 | 	if (old32) { |
| 19 | 		old32->it_interval.tv_sec = old.it_interval.tv_sec; |
| 20 | 		old32->it_interval.tv_usec = old.it_interval.tv_usec; |
| 21 | 		old32->it_value.tv_sec = old.it_value.tv_sec; |
| 22 | 		old32->it_value.tv_usec = old.it_value.tv_usec; |
| 23 | 	} |
| 24 | 	return 0; |
| 25 | } |