Skip to content

Commit 4e604a7

Browse files
committed
Add Util support
1 parent e1626f8 commit 4e604a7

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed

Sources/OpenBox/Util/assert.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// assert.cpp
3+
// OpenBox
4+
5+
#include "assert.hpp"
6+
#include "log.hpp"
7+
8+
char* error_message = nullptr;
9+
10+
namespace OB {
11+
void precondition_failure(const char *format, ...) {
12+
char* s = nullptr;
13+
va_list va;
14+
va_start(va, format);
15+
vasprintf(&s, format, va);
16+
va_end(va);
17+
if (s != nullptr) {
18+
#if OB_TARGET_OS_DARWIN
19+
os_log_error(error_log(), "precondition failure: %s", s);
20+
#endif /* OB_TARGET_OS_DARWIN */
21+
if (error_message == nullptr) {
22+
asprintf(&error_message, "OpenGraph precondition failure: %s.\n", s);
23+
}
24+
free(s);
25+
}
26+
abort();
27+
}
28+
29+
void non_fatal_precondition_failure(const char *format, ...) {
30+
char* s = nullptr;
31+
va_list va;
32+
va_start(va, format);
33+
vasprintf(&s, format, va);
34+
va_end(va);
35+
if (s != nullptr) {
36+
#if OB_TARGET_OS_DARWIN
37+
os_log_fault(error_log(), "precondition failure: %s", s);
38+
#endif /* OB_TARGET_OS_DARWIN */
39+
free(s);
40+
}
41+
return;
42+
}
43+
} /* OB */

Sources/OpenBox/Util/assert.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// assert.hpp
3+
// OpenBox
4+
5+
#ifndef assert_hpp
6+
#define assert_hpp
7+
8+
#include "OBBase.h"
9+
10+
namespace OB {
11+
void precondition_failure(const char *format, ...) __cold __dead2;
12+
void non_fatal_precondition_failure(const char *format, ...);
13+
} /* OB */
14+
15+
#endif /* assert_hpp */

Sources/OpenBox/Util/log.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// OGLog.cpp
3+
// OpenBox
4+
5+
#include "log.hpp"
6+
7+
#if OB_TARGET_OS_DARWIN
8+
9+
namespace OB {
10+
os_log_t misc_log() {
11+
static os_log_t log = os_log_create("org.openswiftuiproject.openbox", "misc");
12+
return log;
13+
}
14+
os_log_t error_log() {
15+
static os_log_t log = os_log_create("org.openswiftuiproject.openbox", "error");
16+
return log;
17+
}
18+
} /* OB */
19+
20+
#endif /* OB_TARGET_OS_DARWIN */

Sources/OpenBox/Util/log.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// log.hpp
3+
// OpenBox
4+
5+
#ifndef log_hpp
6+
#define log_hpp
7+
8+
#include "OBBase.h"
9+
10+
#if OB_TARGET_OS_DARWIN
11+
12+
#include <os/log.h>
13+
14+
namespace OB {
15+
os_log_t misc_log();
16+
os_log_t error_log();
17+
} /* OB */
18+
19+
#endif /* OB_TARGET_OS_DARWIN */
20+
21+
#endif /* log_hpp */

0 commit comments

Comments
 (0)