blob: f251011c51414f294c03de1a2bf30d763a449330 (
plain)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#ifndef BACKEND_UTIL_H_
#define BACKEND_UTIL_H_
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <unistd.h>
#include "list.h"
#define __stringify(x) #x
#define stringify(x) __stringify(x)
#define min(x, y) ({ \
__typeof__(x) __x = (x); \
__typeof__(y) __y = (y); \
__x < __y ? __x : __y; \
})
#define max(a, b) ({ \
__typeof__(a) __a = (a); \
__typeof__(b) __b = (b); \
__a > __b ? __a : __b; \
})
#define clamp(v, mi, ma) max(min(v, ma), mi)
#define round_up(n, s) ((((n) + (s) - 1) / (s)) * (s))
#define div_round_up(x, d) ({ \
__typeof__(x) __x = (x); \
__typeof__(d) __d = (d); \
(__x + __d - 1) / __d; \
})
#define div_round(x, d) ({ \
__typeof__(x) __x = (x); \
__typeof__(d) __d = (d); \
(__x + (__d / 2)) / __d; \
})
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define compiler_barrier() __asm__ __volatile__("" : : : "memory")
#define ALIGN(x) __attribute__((__aligned__(x)))
#define ALIGN_MAX ALIGN(__BIGGEST_ALIGNMENT__)
void msleep(unsigned int msecs);
char * string_strip(char *str);
char * string_split(char *str, int (*sep_match)(int c));
static inline void * zalloc(size_t size)
{
return calloc(1, size);
}
static inline int strempty(const char *s)
{
return (s == NULL) || (s[0] == '\0');
}
uint_fast8_t tiny_hash(const char *str);
pid_t subprocess_exec(const char *_command);
#endif /* BACKEND_UTIL_H_ */
|