summaryrefslogtreecommitdiff
path: root/libc/unistd/sleep.c
diff options
context:
space:
mode:
authorDavid McCullough <davidm@snapgear.com>2003-05-14 05:10:58 +0000
committerDavid McCullough <davidm@snapgear.com>2003-05-14 05:10:58 +0000
commitf9709e559a9abf66546c9fe6cf269167c18b9e74 (patch)
tree9a72b63bfe566dbc2928d0ddbaa319c1e9417a38 /libc/unistd/sleep.c
parentc5ace0d2c9340e3fc72b880ce9364a529b1226f3 (diff)
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 <pauli@snapgear.com>
Diffstat (limited to 'libc/unistd/sleep.c')
-rw-r--r--libc/unistd/sleep.c6
1 files changed, 4 insertions, 2 deletions
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