headers/bsd: Add sys/queue.h.
[haiku.git] / src / system / libroot / posix / unistd / sleep.c
blobec5061d775921fd85f7966c87135216d04414129
1 /*
2 ** Copyright 2001, Manuel J. Petit. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
4 */
6 #include <unistd.h>
8 #include <pthread.h>
10 #include <syscalls.h>
13 unsigned
14 sleep(unsigned seconds)
16 bigtime_t usecs;
17 bigtime_t start;
18 int err;
20 start = system_time();
22 usecs = 1000000;
23 usecs *= (bigtime_t) seconds;
25 err = snooze_until(start + usecs, B_SYSTEM_TIMEBASE);
27 pthread_testcancel();
29 if (err)
30 return seconds - (unsigned)((system_time() - start) / 1000000);
32 return 0;