* 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>
@@ -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