浏览代码

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 年之前
父节点
当前提交
f9709e559a
共有 1 个文件被更改,包括 4 次插入2 次删除
  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