summaryrefslogtreecommitdiffstats
path: root/src/util.h
blob: 248b442c2bceab6b719e1e59409be4f09846abdf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#pragma once

#include <stdio.h>

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define ARRLEN(x) (sizeof(x)/sizeof((x)[0]))

#define PANIC(...) panic("" __VA_ARGS__, __FILE__, __LINE__)
#define ASSERT(x) assert((x), __FILE__, __LINE__, #x)

int strnwidth(const char *s, int n);

void panic(const char *msg, const char *file, int line);
void assert(int cond, const char *file, int line, const char *condstr);

char *aprintf(const char *fmtstr, ...);
char *appendstrf(char *alloc, const char *fmtstr, ...);

char *sanitized(const char *instr);

const char *timestr(unsigned int seconds);