-
Notifications
You must be signed in to change notification settings - Fork 1
/
utilities.h
63 lines (51 loc) · 1.36 KB
/
utilities.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
#ifndef UTILITIES_H
#define UTILITIES_H
#ifdef NOTDEFINED
#error "never define NOTDEFINED"
#endif
#ifdef __cplusplus
#include <cstdio>
#include <string>
#include <sstream>
#endif
#include <stdarg.h>
#if !defined(__GNUC__) || __GNUC__ < 2 || \
(__GNUC__ == 2 && __GNUC_MINOR__ < 7) ||\
defined(NEXT)
#ifndef __attribute__
#define __attribute__(__x)
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
extern void diagnostic_set(char *file, int line);
extern void diagnostic_print(char *fmt, ...)
__attribute__ ((__format__ (__printf__, 1, 2)));
#ifdef __cplusplus
}
#endif
#define DIAG(LEVEL,ARG) do { if(DIAGLEVEL >= DIAG##LEVEL) { diagnostic_set(__FILE__,__LINE__); diagnostic_print ARG; } } while(0);
#define DIAGWARN 1
#define DIAGINFO 0
#ifndef DIAGLEVEL
#define DIAGLEVEL DIAGINFO
#endif
#ifdef DEBUG
# define BUG(ARG) ARG
#else
# define BUG(ARG)
#endif
#ifndef CHECK
#define CHECK(EX) do { if(EX) { int err = errno; fprintf(stderr, "operation" \
" \"%s\" failed on line %d: %s (%d)\n", #EX, __LINE__, strerror(err), err); \
abort(); }} while(0)
#endif
#ifndef CHECKALLOC
#define CHECKALLOC(PTR) if(!(PTR)) { fprintf(stderr,"Out of memory when executing %s at %s:%d\n", #PTR, __FILE__, __LINE__); }
#endif
extern char* argv0;
typedef void (*functioncast_t)(void);
extern functioncast_t functioncast(void*generic);
unsigned long long int rnd(void);
#endif