minix/lib/posix/_sleep.c

26 lines
630 B
C
Raw Normal View History

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