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 <Debug.h>
12#include <image.h>
13#include <OS.h>
14
15mode_t __gUmask = 022;
16
17// debugger
18void
19debugger(const char *message)
20{
21	fprintf(stderr, "debugger() called: %s\n", message);
22	exit(1);
23}
24
25// _debuggerAssert
26int
27_debuggerAssert(const char *file, int line, const char *expression)
28{
29	char buffer[2048];
30	snprintf(buffer, sizeof(buffer), "%s:%d: %s\n", file, line, expression);
31	debugger(buffer);
32	return 0;
33}
34
35#ifndef HAIKU_HOST_PLATFORM_HAIKU
36// system_time
37bigtime_t
38system_time(void)
39{
40	struct timeval tm;
41	gettimeofday(&tm, NULL);
42	return (int64)tm.tv_sec * 1000000LL + (int64)tm.tv_usec;
43}
44#endif
45
46// snooze
47status_t
48snooze(bigtime_t amount)
49{
50	if (amount <= 0)
51		return B_OK;
52
53	int64 secs = amount / 1000000LL;
54	int64 usecs = amount % 1000000LL;
55	if (secs > 0) {
56		if (sleep((unsigned)secs) < 0)
57			return errno;
58	}
59
60	if (usecs > 0) {
61		if (usleep((useconds_t)usecs) < 0)
62			return errno;
63	}
64
65	return B_OK;
66}
67
68// snooze_until
69status_t
70snooze_until(bigtime_t time, int timeBase)
71{
72	return snooze(time - system_time());
73}
74