use setitimer function rather than syscall to implement alarm
authorRich Felker <dalias@aerifal.cx>
Mon, 5 Aug 2019 23:55:42 +0000 (19:55 -0400)
committerRich Felker <dalias@aerifal.cx>
Tue, 6 Aug 2019 01:16:30 +0000 (21:16 -0400)
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.

src/unistd/alarm.c

index 2e3263ac5986019f57576f6b0777f483b449eba7..a5e0c822a05559ffaa2023ab8b6fca3d20f1af63 100644 (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;
 }