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:
Rich Felker 2019-08-05 19:55:42 -04:00
parent 6818c31c9b
commit f522de81ac
1 changed files with 3 additions and 3 deletions

View File

@ -4,7 +4,7 @@
unsigned alarm(unsigned seconds)
{
struct itimerval it = { .it_value.tv_sec = seconds };
__syscall(SYS_setitimer, ITIMER_REAL, &it, &it);
return it.it_value.tv_sec + !!it.it_value.tv_usec;
struct itimerval it = { .it_value.tv_sec = seconds }, old = { 0 };
setitimer(ITIMER_REAL, &it, &old);
return old.it_value.tv_sec + !!old.it_value.tv_usec;
}