-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbaselib.h
77 lines (57 loc) · 1.63 KB
/
baselib.h
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
/**
** Small lib for commonly used C functions.
**
** -- Kristofer Hallin [email protected]
**
*/
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include <signal.h>
#include <execinfo.h>
#ifndef BASELIB_H
#define BASELIB_H
#endif /* BASELIB_H */
FILE *dbg_fd;
#ifndef STACK_MAX_SIZE
#define STACK_MAX_SIZE 10
#endif
#define BITMASK_CLEAR(b) (b &= ~0xFFFFFFFF)
#define BITMASK_SET(b,v) (b |= v)
#define BITMASK_TEST(b,v) if(b & v)
#define BITMASK_UNSET(b,v) (b &= v)
#ifndef ASSERT_INTERACTIVE
#define ASSERT(c) \
if(c) ; else { ASSERT_FAILURE(c); kill(0, 6); }
#define ASSERT_FAILURE(c) \
fprintf(stderr, "%s: assertion %s failed on line %d in %s\n", \
__func__, #c, __LINE__, __FILE__);
#endif /* ASSERT_INTERACTIVE */
#ifdef ASSERT_INTERACTIVE
#define ASSERT(c) \
if(c) ; else { ASSERT_INTERACTIVE(c); }
#define ASSERT_INTERACTIVE \
int ch = 0; printf("Assertion detected, (I)gnore or (A)bort?\n> "); \
ch = getchar(); if (ch == 'I') ; else if (ch == 'A') kill(0,6);
#endif /* ASSERT_INTERACTIVE */
#define DEBUG_FILE_INIT \
ASSERT(dbg_fd = fopen("debug.log", "w+"));
#define DEBUG_FILE(x) \
fprintf(dbg_fd, "%d, %s: %s\n", time(NULL), __func__, x);
#define DEBUG_FILE_CLOSE \
fclose(dbg_fd);
#define DEBUG(x) \
fprintf(stderr, "%d, %s: %s\n", time(NULL), __func__, x);
#define ERROR_RET -1
#define ERROR(x) \
fprintf(stderr, "%d, %s: %s\n", time(NULL), __func__, x); \
exit(ERROR_RET);
#define MIN(a,b) \
(a > b ? a : b)
#define MAX(a,b) \
(b > a ? b : a)
#define FLIP(a,b) \
a ^= b; b ^= a; a ^= b;
void stacktrace_init(void);
static void stacktrace_print(const int sig);