mirror of git://git.musl-libc.org/musl
use setitimer function rather than syscall to implement alarm
otherwise alarm will break on 32-bit archs when time_t is changed to 64-bit. a second itimerval object is introduced for retrieving the old value, since the setitimer function has restrict-qualified arguments.
This commit is contained in:
parent
6818c31c9b
commit
f522de81ac
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
unsigned alarm(unsigned seconds)
|
unsigned alarm(unsigned seconds)
|
||||||
{
|
{
|
||||||
struct itimerval it = { .it_value.tv_sec = seconds };
|
struct itimerval it = { .it_value.tv_sec = seconds }, old = { 0 };
|
||||||
__syscall(SYS_setitimer, ITIMER_REAL, &it, &it);
|
setitimer(ITIMER_REAL, &it, &old);
|
||||||
return it.it_value.tv_sec + !!it.it_value.tv_usec;
|
return old.it_value.tv_sec + !!old.it_value.tv_usec;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue