util.h (831B)
1#pragma once 2 3#include <unistd.h> 4#include <string.h> 5#include <stdarg.h> 6#include <stdbool.h> 7#include <stdio.h> 8#include <stdint.h> 9#include <stdlib.h> 10 11#define ARRLEN(x) (sizeof(x) / sizeof(*(x))) 12 13#define ABS(a) ((a) > 0 ? (a) : -(a)) 14 15#define MAX(a, b) ((a) > (b) ? (a) : (b)) 16#define MIN(a, b) ((a) > (b) ? (b) : (a)) 17 18#define XORSWAP(a, b) ((a) ^= (b) ^= (a)) 19 20#define CEILDIV(a, b) ((a) / (b) + ((a) % (b) ? 1 : 0)) 21 22__attribute__((noreturn)) void die(const char *fmtstr, ...); 23 24bool readtok(char *buf, size_t buflen, 25 char sep, const char **pos, const char *end); 26int64_t parsei64(const char *str); 27 28char *aprintf(const char *fmtstr, ...); 29char *strdup(const char *str); 30char *apprintf(char *alloc, const char *fmtstr, ...); 31void *memdup(const void *data, size_t size); 32 33void readall(FILE *f, void **data, size_t *read); 34