From 3a9f7e6c9e1f44385c1950edc6267af8eea56a7e Mon Sep 17 00:00:00 2001 From: Fabrice Date: Tue, 3 Mar 2026 09:42:37 +0100 Subject: formatting of tokens --- src/common.cc | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/common.cc') diff --git a/src/common.cc b/src/common.cc index de2f6de..5e84c01 100644 --- a/src/common.cc +++ b/src/common.cc @@ -26,7 +26,7 @@ typedef intptr_t isize; #define likely(cond) __builtin_expect(!!(cond), 1) #define unlikely(cond) __builtin_expect(!!(cond), 0) #define containerof(type, member, ptr) \ - ((type *)((char *)(ptr) - offsetof(type, member))) + ((type*)((char*)(ptr) - offsetof(type, member))) /* error handling sort of */ [[noreturn]] void panic_impl(const char* file, i32 line, const char* fmt, ...) { @@ -72,25 +72,24 @@ struct Slice { } const T* operator[](usize index) const { - assert(index < this->size()); + assert(index < this->total_length()); return this->ptr + index; } - inline usize size() const { return this->length * sizeof(T); } + inline usize total_length() const { return this->length * sizeof(T); } }; -template -bool slice_write(const Slice* slice, FILE* stream) { - assert_neq(slice, nullptr); +typedef Slice String; + +bool string_write(const String* s, FILE* stream) { + assert_neq(s, nullptr); assert_neq(stream, nullptr); - usize rc = fwrite(slice->ptr, sizeof(T), slice->length, stream); - if (rc == 0 || slice->size() > rc) return false; + i32 rc = fprintf(stream, "%.*s", (i32)s->length, s->ptr); + if (unlikely(rc < 0)) return false; return true; } -typedef Slice String; - /* linked list */ struct Link { -- cgit v1.2.3