[uClibc-cvs] uClibc/libc/unistd sleep.c,1.5,1.6

David McCullough davidm at uclibc.org
Wed May 14 05:11:01 UTC 2003


Update of /var/cvs/uClibc/libc/unistd
In directory winder:/tmp/cvs-serv14019

Modified Files:
	sleep.c 
Log Message:

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 at snapgear.com>



Index: sleep.c
===================================================================
RCS file: /var/cvs/uClibc/libc/unistd/sleep.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- sleep.c	2 Jan 2002 12:12:41 -0000	1.5
+++ sleep.c	14 May 2003 05:10:58 -0000	1.6
@@ -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



More information about the uClibc-cvs mailing list