aboutsummaryrefslogtreecommitdiff
path: root/cassert
diff options
context:
space:
mode:
Diffstat (limited to 'cassert')
-rw-r--r--cassert/CMakeLists.txt8
-rw-r--r--cassert/include/cassert.h29
2 files changed, 37 insertions, 0 deletions
diff --git a/cassert/CMakeLists.txt b/cassert/CMakeLists.txt
new file mode 100644
index 0000000..855f261
--- /dev/null
+++ b/cassert/CMakeLists.txt
@@ -0,0 +1,8 @@
1cmake_minimum_required(VERSION 3.0)
2
3project(cassert)
4
5add_library(cassert INTERFACE)
6
7target_include_directories(cassert INTERFACE
8 include)
diff --git a/cassert/include/cassert.h b/cassert/include/cassert.h
new file mode 100644
index 0000000..3349b55
--- /dev/null
+++ b/cassert/include/cassert.h
@@ -0,0 +1,29 @@
1#pragma once
2
3#include <assert.h> // For convenience, bring in soft assertions with assert().
4#include <signal.h>
5
6// Allow the client to define their own LOGE() macro.
7#ifndef LOGE
8#include <stdio.h>
9#define LOGE(...) \
10 { \
11 fprintf(stderr, "[ASSERT] %s:%d: ", __FILE__, __LINE__); \
12 fprintf(stderr, __VA_ARGS__); \
13 fprintf(stderr, "\n"); \
14 }
15#endif // LOGE
16
17#define TRAP() raise(SIGTRAP)
18
19/// Unconditional hard assert.
20#define FAIL(message) \
21 LOGE(message); \
22 TRAP();
23
24/// Conditional hard assert.
25#define ASSERT(condition) \
26 if (!condition) { \
27 LOGE("Assertion failed: " #condition) \
28 TRAP(); \
29 }