From f522de81ac88dddb58266c15bcfaa044c4065e19 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 5 Aug 2019 19:55:42 -0400 Subject: [PATCH] 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. --- src/unistd/alarm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/unistd/alarm.c b/src/unistd/alarm.c index 2e3263ac..a5e0c822 100644 --- a/src/unistd/alarm.c +++ b/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; } -- 2.25.1