typedef unsigned char byte; #define KSTR(s) s, (sizeof(s) - 1) #define KSTR_LEN(s) (sizeof(s) - 1) #define arrsz(a) (sizeof(a)/sizeof(a[0])) #define STRINGIFY(x) #x #define TOSTRING(x) STRINGIFY(x) #define warn(...) do{fprintf(stderr, "WARN " __VA_ARGS__); }while(0) #define warnsys(...) do{fprintf(stderr, "WARN " __VA_ARGS__); perror(" sys"); }while(0) #define die(...) do{fprintf(stderr, __VA_ARGS__); exit(1); }while(0) #define diesys(...) do{fprintf(stderr, __VA_ARGS__); perror(" sys"); exit(1);}while(0) #define debug(...) do{fprintf(stderr, __VA_ARGS__); }while(0) #define unless(x) if(!(x)) #define assert(c) if(!(c)){ fputs("assertion failed: " __FILE__ ":" TOSTRING(__LINE__) ": " #c "\n", stderr); __builtin_trap(); } #define log(...) do { \ struct timespec ts; \ clock_gettime(CLOCK_REALTIME, &ts); \ struct tm tm; \ char ts_buf[32]; \ strftime(ts_buf, sizeof(ts_buf), "%Y-%m-%d %H:%M:%S", gmtime_r(&ts.tv_sec, &tm)); \ fprintf(stderr, "[%s.%03ldZ] ", ts_buf, ts.tv_nsec / 1000000); \ fprintf(stderr, __VA_ARGS__); \ } while(0) typedef uint8_t byte; 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;