aboutsummaryrefslogtreecommitdiffhomepage
path: root/common.c
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-08-22 23:28:25 +0900
committernsfisis <nsfisis@gmail.com>2025-08-22 23:28:25 +0900
commit9c202a496e75903fe37e5c19cb97c98eba6e35f2 (patch)
tree52de494a4717a3c30c4bacb9dd9b91980be2a575 /common.c
parent0ac6ac95283735dd70ebf55b26ef78a4c32c31de (diff)
downloadducc-9c202a496e75903fe37e5c19cb97c98eba6e35f2.tar.gz
ducc-9c202a496e75903fe37e5c19cb97c98eba6e35f2.tar.zst
ducc-9c202a496e75903fe37e5c19cb97c98eba6e35f2.zip
chore: move *.c and *.h files to src/
Diffstat (limited to 'common.c')
-rw-r--r--common.c39
1 files changed, 0 insertions, 39 deletions
diff --git a/common.c b/common.c
deleted file mode 100644
index 1b89f8c..0000000
--- a/common.c
+++ /dev/null
@@ -1,39 +0,0 @@
-void fatal_error(const char* msg, ...) {
- va_list args;
- va_start(args, msg);
- vfprintf(stderr, msg, args);
- va_end(args);
- fprintf(stderr, "\n");
- exit(1);
-}
-
-#define unreachable() fatal_error("%s:%d: unreachable", __FILE__, __LINE__)
-
-#define unimplemented() fatal_error("%s:%d: unimplemented", __FILE__, __LINE__)
-
-struct StrBuilder {
- size_t len;
- size_t capacity;
- char* buf;
-};
-typedef struct StrBuilder StrBuilder;
-
-void strbuilder_init(StrBuilder* b) {
- b->len = 0;
- b->capacity = 16;
- b->buf = calloc(b->capacity, sizeof(char));
-}
-
-// `size` must include a trailing null byte.
-void strbuilder_reserve(StrBuilder* b, size_t size) {
- if (size <= b->capacity)
- return;
- b->capacity *= 2;
- b->buf = realloc(b->buf, b->capacity * sizeof(char));
- memset(b->buf + b->len, 0, (b->capacity - b->len) * sizeof(char));
-}
-
-void strbuilder_append_char(StrBuilder* b, int c) {
- strbuilder_reserve(b, b->len + 1 + 1);
- b->buf[b->len++] = c;
-}