Browse Source

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.
Rich Felker 5 years ago
parent
commit
f522de81ac
1 changed files with 3 additions and 3 deletions
  1. 3 3
      src/unistd/alarm.c

+ 3 - 3
src/unistd/alarm.c

@@ -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;
 }