Browse Source

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>
David McCullough 22 years ago
parent
commit
f9709e559a
1 changed files with 4 additions and 2 deletions
  1. 4 2
      libc/unistd/sleep.c

+ 4 - 2
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