commit 85674f738ed181c0a42531e0ac8a4c09b156ab46
parent cf6f735c777f6f3313c16d2cdf28009dd0ffbdaf
Author: Henry Wilson <henry@henryandlizzy.uk>
Date: Sun, 28 Dec 2025 20:32:32 +0000
Assertions for all
Diffstat:
3 files changed, 5 insertions(+), 8 deletions(-)
diff --git a/linux.hpp b/linux.hpp
@@ -41,6 +41,8 @@ enum {
DT_WHT = 14,
};
+#define assert(condition) if (not (condition)) __builtin_trap();
+
template <typename T>
struct span
{
@@ -105,8 +107,7 @@ struct syscall_result
explicit operator bool() const { return val >= 0; }
T operator*() const
{
- if (!*this)
- __builtin_trap();
+ assert(*this);
if constexpr (__is_pointer(T))
return reinterpret_cast<T>(val);
else
@@ -114,8 +115,7 @@ struct syscall_result
}
errno_t err() const
{
- if (*this)
- __builtin_trap();
+ assert(not *this);
return static_cast<errno_t>(val);
}
private:
diff --git a/ls.cpp b/ls.cpp
@@ -1,7 +1,5 @@
#include "linux.hpp"
-#define assert(x) if (!(x)) __builtin_trap()
-
static size_t strlen(char const* p)
{
char const* const begin = p;
diff --git a/writer.cpp b/writer.cpp
@@ -18,8 +18,7 @@ struct fd_writer : writer
void write(span<char const> data) override
{
- if (*::write(out, data) != data.size())
- __builtin_trap();
+ assert(*::write(out, data) == data.size());
}
private:
file out;