From e4ab3198e16d6109bb38a0cca026af608b35e873 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 10 Aug 2014 13:11:52 -0600 Subject: [PATCH] Slightly improved nanosecond calculation --- libc/unistd/lib_usleep.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libc/unistd/lib_usleep.c b/libc/unistd/lib_usleep.c index e48ae4267e..3088c7737b 100644 --- a/libc/unistd/lib_usleep.c +++ b/libc/unistd/lib_usleep.c @@ -129,14 +129,16 @@ int usleep(useconds_t usec) { struct timespec rqtp; + time_t sec; int ret = 0; if (usec) { /* Let nanosleep() do all of the work. */ - rqtp.tv_sec = usec / 1000000; - rqtp.tv_nsec = (usec % 1000000) * 1000; + sec = usec / 1000000; + rqtp.tv_sec = sec; + rqtp.tv_nsec = (usec - (sec * 1000000)) * 1000; ret = nanosleep(&rqtp, NULL); }