2009-08-16 14:13:33 +02:00
|
|
|
/* sleep() - Sleep for a number of seconds. Author: Erik van der Kouwe
|
2009-08-16 00:14:48 +02:00
|
|
|
* 25 July 2009
|
2009-08-16 14:13:33 +02:00
|
|
|
* (Avoids interfering with alarm/setitimer by using select, like usleep)
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <lib.h>
|
|
|
|
#define sleep _sleep
|
2009-08-16 14:13:33 +02:00
|
|
|
#include <signal.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
2005-04-21 16:53:53 +02:00
|
|
|
#include <time.h>
|
2009-08-16 14:13:33 +02:00
|
|
|
#include <sys/select.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
unsigned sleep(unsigned sleep_seconds)
|
|
|
|
{
|
2009-08-16 00:14:48 +02:00
|
|
|
struct timespec rqtp, rmtp;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2009-08-16 14:13:33 +02:00
|
|
|
/* nanosleep implements this call; ignore failure, it cannot be reported */
|
2009-08-16 00:14:48 +02:00
|
|
|
rqtp.tv_sec = sleep_seconds;
|
|
|
|
rqtp.tv_nsec = 0;
|
|
|
|
nanosleep(&rqtp, &rmtp);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2009-08-16 00:14:48 +02:00
|
|
|
/* round remainder up to seconds */
|
|
|
|
return rmtp.tv_sec + ((rmtp.tv_nsec > 0) ? 1 : 0);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|