diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-08-24 23:55:22 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-08-25 00:18:08 +0900 |
| commit | 36da139565202a9a39d1e4261ab8bf950041518b (patch) | |
| tree | c8e8867edc4e4fed94403331b8a7837e9951d9af /src/common.h | |
| parent | 5bbc4414b8178ff924444857ac05e5b06cf0e651 (diff) | |
| download | ducc-36da139565202a9a39d1e4261ab8bf950041518b.tar.gz ducc-36da139565202a9a39d1e4261ab8bf950041518b.tar.zst ducc-36da139565202a9a39d1e4261ab8bf950041518b.zip | |
feat: separate compilation
Diffstat (limited to 'src/common.h')
| -rw-r--r-- | src/common.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/common.h b/src/common.h new file mode 100644 index 0000000..f8f6b1d --- /dev/null +++ b/src/common.h @@ -0,0 +1,37 @@ +#ifndef DUCC_COMMON_H +#define DUCC_COMMON_H + +#include "std.h" + +void fatal_error(const char* msg, ...); + +#define unreachable() fatal_error("%s:%d: unreachable", __FILE__, __LINE__) +#define unimplemented() fatal_error("%s:%d: unimplemented", __FILE__, __LINE__) + +BOOL str_ends_with(const char* s, const char* suffix); + +struct StrBuilder { + size_t len; + size_t capacity; + char* buf; +}; +typedef struct StrBuilder StrBuilder; + +void strbuilder_init(StrBuilder* b); +// `size` must include a trailing null byte. +void strbuilder_reserve(StrBuilder* b, size_t size); +void strbuilder_append_char(StrBuilder* b, int c); +void strbuilder_append_string(StrBuilder* b, const char* s); + +struct StrArray { + size_t len; + size_t capacity; + const char** data; +}; +typedef struct StrArray StrArray; + +void strings_init(StrArray* strings); +void strings_reserve(StrArray* strings, size_t size); +int strings_push(StrArray* strings, const char* str); + +#endif |
