aboutsummaryrefslogtreecommitdiffstats
path: root/src/common/util.h
blob: 02fcdb8cb2e7685088606cd0b2007deecfd54a28 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#pragma once

#include <unistd.h>
#include <string.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

#define ARRLEN(x) (sizeof(x) / sizeof(*(x)))

#define ABS(a) ((a) > 0 ? (a) : -(a))

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

#define XORSWAP(a, b) ((a) ^= (b) ^= (a))

#define CEILDIV(a, b) ((a) / (b) + ((a) % (b) ? 1 : 0))

__attribute__((noreturn)) void die(const char *fmtstr, ...);

bool readtok(char *buf, size_t buflen,
	char sep, const char **pos, const char *end);
int64_t parsei64(const char *str);

char *aprintf(const char *fmtstr, ...);
char *strdup(const char *str);
char *apprintf(char *alloc, const char *fmtstr, ...);
void *memdup(const void *data, size_t size);

void readall(FILE *f, void **data, size_t *read);