xref: /haiku/src/system/libroot/posix/unistd/sleep.c (revision c2f0a314a012bea8e4ebb35b8ce9e1a85c798727)
1 /*
2 ** Copyright 2001, Manuel J. Petit. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
4 */
5 
6 #include <unistd.h>
7 #include <syscalls.h>
8 
9 
10 unsigned
11 sleep(unsigned seconds)
12 {
13 	bigtime_t usecs;
14 	bigtime_t start;
15 	int err;
16 
17 	start = system_time();
18 
19 	usecs = 1000000;
20 	usecs *= (bigtime_t) seconds;
21 
22 	err = snooze_until(start + usecs, B_SYSTEM_TIMEBASE);
23 	if (err)
24 		return seconds - (unsigned)((system_time() - start) / 1000000);
25 
26 	return 0;
27 }
28