btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / build / libroot / misc.cpp
blob52c74f6f0871ff58e97cf01356cac4287e0844ec
2 #include <BeOSBuildCompatibility.h>
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>
11 #include <Debug.h>
12 #include <image.h>
13 #include <OS.h>
15 mode_t __gUmask = 022;
17 // debugger
18 void
19 debugger(const char *message)
21 fprintf(stderr, "debugger() called: %s\n", message);
22 exit(1);
25 // _debuggerAssert
26 int
27 _debuggerAssert(const char *file, int line, const char *expression)
29 char buffer[2048];
30 snprintf(buffer, sizeof(buffer), "%s:%d: %s\n", file, line, expression);
31 debugger(buffer);
32 return 0;
35 // system_time
36 bigtime_t
37 system_time(void)
39 struct timeval tm;
40 gettimeofday(&tm, NULL);
41 return (int64)tm.tv_sec * 1000000LL + (int64)tm.tv_usec;
44 // snooze
45 status_t
46 snooze(bigtime_t amount)
48 if (amount <= 0)
49 return B_OK;
51 int64 secs = amount / 1000000LL;
52 int64 usecs = amount % 1000000LL;
53 if (secs > 0) {
54 if (sleep((unsigned)secs) < 0)
55 return errno;
58 if (usecs > 0) {
59 if (usleep((useconds_t)usecs) < 0)
60 return errno;
63 return B_OK;
66 // snooze_until
67 status_t
68 snooze_until(bigtime_t time, int timeBase)
70 return snooze(time - system_time());