mirror of
https://git.musl-libc.org/git/musl
synced 2025-01-08 07:42:09 +03:00
9432bbd4e8
this interface permits a null pointer for where to store the old itimerval being replaced. an early version of the time32 compat shim code had corresponding bugs for lots of functions; apparently setitimer was overlooked when fixing them.
26 lines
938 B
C
26 lines
938 B
C
#include "time32.h"
|
|
#include <time.h>
|
|
#include <sys/time.h>
|
|
|
|
int __setitimer_time32(int which, const struct itimerval32 *restrict new32, struct itimerval32 *restrict old32)
|
|
{
|
|
struct itimerval old;
|
|
int r = setitimer(which, (&(struct itimerval){
|
|
.it_interval.tv_sec = new32->it_interval.tv_sec,
|
|
.it_interval.tv_usec = new32->it_interval.tv_usec,
|
|
.it_value.tv_sec = new32->it_value.tv_sec,
|
|
.it_value.tv_usec = new32->it_value.tv_usec}), &old);
|
|
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_usec = old.it_interval.tv_usec;
|
|
old32->it_value.tv_sec = old.it_value.tv_sec;
|
|
old32->it_value.tv_usec = old.it_value.tv_usec;
|
|
}
|
|
return 0;
|
|
}
|