bitwise util.h
 1#pragma once
 2
 3#include <stddef.h>
 4#include <stdint.h>
 5#include <stdnoreturn.h>
 6#define nil ((void *)0)
 7
 8typedef int8_t i8;
 9typedef int16_t i16;
10typedef int32_t i32;
11typedef int64_t i64;
12typedef uint8_t u8;
13typedef uint16_t u16;
14typedef uint32_t u32;
15typedef uint64_t u64;
16typedef ptrdiff_t isize;
17typedef size_t usize;
18
19extern const char *PROG;
20
21noreturn void diev(int, const char *const *, usize);
22
23#define STRS(...) (const char *const[]){__VA_ARGS__}, \
24	          sizeof((const char *const[]){__VA_ARGS__}) / sizeof(const char *)
25#define die(...) diev(0, STRS(__VA_ARGS__))
26#define diesys(...) diev(1, STRS(__VA_ARGS__))
27
28void *alloc(usize);
29void *zalloc(usize);
30void *allocre(void *, usize);
31
32typedef struct stralloc {
33	char *s;
34	usize len; /* how many bytes are in use */
35	usize a; /* how many are allocated */
36} stralloc;
37
38void sagrow(stralloc *, usize);
39void sacatb(stralloc *, const char *, usize);
40void sa0(stralloc *);
41#define sacatl(sa, lit) sacatb((sa), (lit), sizeof(lit) - 1)
42int openreadclose(const char *, stralloc *);
43
44#define FMTUSIZE 20
45usize fmtusize(char *, usize);
46void putnum(usize);