From f9709e559a9abf66546c9fe6cf269167c18b9e74 Mon Sep 17 00:00:00 2001 From: David McCullough Date: Wed, 14 May 2003 05:10:58 +0000 Subject: Sleep was returning the wrong value because: * nanosleep returns the remaining time, not the time slept * nanosleep only fills out the remaining time if it returns -1 (ie., the sleep was interrupted) Fix from Paul Dale --- libc/unistd/sleep.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'libc/unistd') diff --git a/libc/unistd/sleep.c b/libc/unistd/sleep.c index f8c57fc89..2b3187ebc 100644 --- a/libc/unistd/sleep.c +++ b/libc/unistd/sleep.c @@ -29,12 +29,14 @@ * fine unless you are messing with SIGCHLD... */ unsigned int sleep (unsigned int sec) { + unsigned int res; struct timespec ts = { tv_sec: (long int) sec, tv_nsec: 0 }; - nanosleep(&ts, &ts); - return(sec-ts.tv_sec); + res = nanosleep(&ts, &ts); + if (res) res = (unsigned int) ts.tv_sec + (ts.tv_nsec >= 500000000L); + return res; } #else -- cgit v1.2.3