aboutsummaryrefslogtreecommitdiff
path: root/utils.h
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-09-24 20:22:00 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-09-24 20:22:00 -0400
commit3d5944a732e34b6dd01921dee991dee54af47e18 (patch)
tree97d17a4e7feb97d367060a184907a6978352d5ec /utils.h
parent20c11b29b3a63c221cac942a17bf9abcf8b9bafe (diff)
Autoformatting with clang-format
Diffstat (limited to 'utils.h')
-rw-r--r--utils.h45
1 files changed, 22 insertions, 23 deletions
diff --git a/utils.h b/utils.h
index 9779f78..aa2ccc4 100644
--- a/utils.h
+++ b/utils.h
@@ -6,9 +6,8 @@
#include <err.h>
#include <stdarg.h>
#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <stdlib.h> // IWYU pragma: export
+#include <string.h> // IWYU pragma: export
#include <unistd.h>
#ifndef auto
@@ -18,35 +17,35 @@
#define S1(x) #x
#define S2(x) S1(x)
-#define require(e, msg) ({\
- __typeof__(e) __expr = e; \
- if (_Generic(__expr, int: (ssize_t)__expr < 0, ssize_t: (ssize_t)__expr < 0, default: !__expr)) errx(1, __FILE__":"S2(__LINE__)": " msg); \
- __expr; \
-})
+#define require(e, msg) \
+ ({ \
+ __typeof__(e) __expr = e; \
+ if (_Generic(__expr, int: (ssize_t)__expr < 0, ssize_t: (ssize_t)__expr < 0, default: !__expr)) \
+ errx(1, __FILE__ ":" S2(__LINE__) ": " msg); \
+ __expr; \
+ })
-#define When(x, _tag) ((x)->type == _tag ? &(x)->__tagged._tag : (errx(1, __FILE__ ":%d This was supposed to be a " # _tag "\n", __LINE__), &(x)->__tagged._tag))
+#define When(x, _tag) \
+ ((x)->type == _tag \
+ ? &(x)->__tagged._tag \
+ : (errx(1, __FILE__ ":%d This was supposed to be a " #_tag "\n", __LINE__), &(x)->__tagged._tag))
#ifndef public
-#define public __attribute__ ((visibility ("default")))
+#define public __attribute__((visibility("default")))
#endif
#define new(t) require(calloc(1, sizeof(t)), "`new(" #t ")` allocation failure")
#define checked_strdup(s) require(strdup(s), "`checked_strdup(" #s ")` allocation failure")
-#define grow(arr,n) require(realloc(arr,sizeof(arr[0])*(n)), "`grow(" #arr ", " #n ")` allocation failure")
+#define grow(arr, n) require(realloc(arr, sizeof(arr[0]) * (n)), "`grow(" #arr ", " #n ")` allocation failure")
#define streq(a, b) (strcmp(a, b) == 0)
-__attribute__((nonnull(1)))
-char unescapechar(const char *escaped, const char **after, const char *end);
-__attribute__((pure, nonnull))
-const char *after_name(const char *str, const char *end);
-__attribute__((pure, nonnull, returns_nonnull))
-const char *after_spaces(const char *str, bool skip_nl, const char *end);
-__attribute__((nonnull))
-bool matchchar(const char **str, char c, bool skip_nl, const char *end);
-__attribute__((nonnull))
-bool matchstr(const char **str, const char *target, bool skip_nl, const char *end);
-__attribute__((nonnull))
-void delete(void *p);
+__attribute__((nonnull(1))) char unescapechar(const char *escaped, const char **after, const char *end);
+__attribute__((pure, nonnull)) const char *after_name(const char *str, const char *end);
+__attribute__((pure, nonnull, returns_nonnull)) const char *after_spaces(const char *str, bool skip_nl,
+ const char *end);
+__attribute__((nonnull)) bool matchchar(const char **str, char c, bool skip_nl, const char *end);
+__attribute__((nonnull)) bool matchstr(const char **str, const char *target, bool skip_nl, const char *end);
+__attribute__((nonnull)) void delete(void *p);
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0