#ifndef COMMON_CC #define COMMON_CC #include #include /* typedefs for common types */ typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32; typedef uint64_t u64; typedef int8_t i8; typedef int16_t i16; typedef int32_t i32; typedef int64_t i64; typedef uintptr_t usize; typedef intptr_t isize; /* slice and string handling */ template struct Slice { T* ptr; usize length; Slice() : ptr(nullptr), length(0) {} Slice(T* ptr, usize length) : ptr(ptr), length(length) {} T* operator[](usize index) { return ptr + index; } inline usize size() const { return this->length * sizeof(T); } }; template bool slice_write(const Slice* slice, FILE* stream) { usize rc = fwrite(slice->ptr, sizeof(T), slice->length, stream); if(rc == 0 || slice->size() > rc) return false; return true; } typedef Slice String; #endif