1 2 #include <BeOSBuildCompatibility.h> 3 4 #include <errno.h> 5 #include <stdio.h> 6 #include <stdlib.h> 7 #include <unistd.h> 8 #include <sys/stat.h> 9 #include <sys/time.h> 10 11 #include <image.h> 12 #include <OS.h> 13 14 mode_t __gUmask = 022; 15 16 // debugger 17 void 18 debugger(const char *message) 19 { 20 fprintf(stderr, "debugger() called: %s\n", message); 21 exit(1); 22 } 23 24 // system_time 25 bigtime_t 26 system_time(void) 27 { 28 struct timeval tm; 29 gettimeofday(&tm, NULL); 30 return (int64)tm.tv_sec * 1000000LL + (int64)tm.tv_usec; 31 } 32 33 // snooze 34 status_t 35 snooze(bigtime_t amount) 36 { 37 if (amount <= 0) 38 return B_OK; 39 40 int64 secs = amount / 1000000LL; 41 int64 usecs = amount % 1000000LL; 42 if (secs > 0) { 43 if (sleep((unsigned)secs) < 0) 44 return errno; 45 } 46 47 if (usecs > 0) { 48 if (usleep((useconds_t)usecs) < 0) 49 return errno; 50 } 51 52 return B_OK; 53 } 54 55 // snooze_until 56 status_t 57 snooze_until(bigtime_t time, int timeBase) 58 { 59 return snooze(time - system_time()); 60 } 61