#include <BeOSBuildCompatibility.h>
 
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/time.h>
 
#include <Debug.h>
#include <image.h>
#include <OS.h>
 
mode_t __gUmask = 022;
 
// debugger
void
debugger(const char *message)
{
	fprintf(stderr, "debugger() called: %s\n", message);
	exit(1);
}
 
// _debuggerAssert
int
_debuggerAssert(const char *file, int line, const char *expression)
{
	char buffer[2048];
	snprintf(buffer, sizeof(buffer), "%s:%d: %s\n", file, line, expression);
	debugger(buffer);
	return 0;
}
 
#ifndef HAIKU_HOST_PLATFORM_HAIKU
// system_time
bigtime_t
system_time(void)
{
	struct timeval tm;
	gettimeofday(&tm, NULL);
	return (int64)tm.tv_sec * 1000000LL + (int64)tm.tv_usec;
}
#endif
 
// snooze
status_t
snooze(bigtime_t amount)
{
	if (amount <= 0)
		return B_OK;
 
	int64 secs = amount / 1000000LL;
	int64 usecs = amount % 1000000LL;
	if (secs > 0) {
		if (sleep((unsigned)secs) < 0)
			return errno;
	}
 
	if (usecs > 0) {
		if (usleep((useconds_t)usecs) < 0)
			return errno;
	}
 
	return B_OK;
}
 
// snooze_until
status_t
snooze_until(bigtime_t time, int timeBase)
{
	return snooze(time - system_time());
}

V547 Expression 'sleep((unsigned) secs) < 0' is always false. Unsigned type value is never < 0.