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 8#include <pthread.h> 9 10#include <syscalls.h> 11 12 13unsigned 14sleep(unsigned seconds) 15{ 16 bigtime_t usecs; 17 bigtime_t start; 18 int err; 19 20 start = system_time(); 21 22 usecs = 1000000; 23 usecs *= (bigtime_t) seconds; 24 25 err = snooze_until(start + usecs, B_SYSTEM_TIMEBASE); 26 27 pthread_testcancel(); 28 29 if (err) 30 return seconds - (unsigned)((system_time() - start) / 1000000); 31 32 return 0; 33} 34