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:
1 parent
6818c31c9b
commit
f522de81ac
1 file changed
+3
-3
+3
-3
@@ -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;
|
||||
}
|
||||
Reference in new issue
Block a user