-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasedefs.h
More file actions
82 lines (64 loc) · 1.72 KB
/
Copy pathbasedefs.h
File metadata and controls
82 lines (64 loc) · 1.72 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef BASEDEFS_H
#define BASEDEFS_H
#define QSTR(x__) #x__
#define Q(x__) QSTR(x__)
#define AK_LLEN(l__) (sizeof(l__) - 1)
#if __GNUC__ >= 4
#define AUR __attribute__((warn_unused_result))
#define AK_ALLOC __attribute__((malloc)) __attribute__((warn_unused_result))
#define AK_NORET __attribute__((noreturn))
#else
#define AUR
#define AK_ALLOC
#define AK_NORET
#endif
#define AK_CONSTRUCTOR __attribute__((constructor))
#define AK_DESTRUCTOR __attribute__((destructor))
#ifndef O_CLOEXEC
#define O_CLOEXEC 0
#endif
#define LLEN(l__) (sizeof(l__) - 1)
/* Align x_ with v_. v_ must be simple power for 2 value. */
#define ROUNDUP(x_, v_) (((x_) + (v_) - 1) & ~((v_) - 1))
/* Round down align x_ with v_. v_ must be simple power for 2 value. */
#define ROUNDOWN(x_, v_) ((x_) - ((x_) & ((v_) - 1)))
#ifdef __GNUC__
#define RCGO(rc__, label__) if (__builtin_expect((!!(rc__)), 0)) goto label__
#else
#define RCGO(rc__, label__) if (rc__) goto label__
#endif
#define RCHECK(rc__, label__, expr__) \
rc__ = expr__; \
RCGO(rc__, label__)
#define RCC(rc__, label__, expr__) RCHECK(rc__, label__, expr__)
#define RCN(label__, expr__) \
rc = (expr__); \
if (rc) { \
akerror(rc, 0, 0); \
goto label__; \
}
#ifndef MIN
#define MIN(a_, b_) ((a_) < (b_) ? (a_) : (b_))
#endif
#ifndef MAX
#define MAX(a_, b_) ((a_) > (b_) ? (a_) : (b_))
#endif
#ifndef _AMALGAMATE_
#include <stdlib.h>
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
#endif
struct value {
void *buf;
size_t len;
int error;
};
static inline int value_destroy(struct value *v) {
if (v->buf) {
free(v->buf);
v->buf = 0;
}
return v->error;
}
#endif