-
Notifications
You must be signed in to change notification settings - Fork 12
/
coru_util.h
71 lines (60 loc) · 1.31 KB
/
coru_util.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
/*
* coru utilities and config
*
* Copyright (c) 2019 Christopher Haster
* Distributed under the MIT license
*
* Can be overridden by users with their own configuration by defining
* CORU_CONFIG as a header file (-DCORU_CONFIG=coru_config.h)
*
* If CORU_CONFIG is defined, none of the default definitions will be emitted
* and must be provided by the user's config file. To start, I would suggest
* copying coru_util.h and modifying as needed.
*/
#ifndef CORU_UTIL_H
#define CORU_UTIL_H
#ifdef CORU_CONFIG
#define CORU_STRINGIZE(x) CORU_STRINGIZE2(x)
#define CORU_STRINGIZE2(x) #x
#include CORU_STRINGIZE(CORU_CONFIG)
#else
// Standard includes, mostly needed for type definitions
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#ifndef CORU_NO_MALLOC
#include <stdlib.h>
#endif
#ifndef CORU_NO_ASSERT
#include <assert.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
// Runtime assertions
#ifndef CORU_NO_ASSERT
#define CORU_ASSERT(test) assert(test)
#else
#define CORU_ASSERT(test)
#endif
// Optional memory allocation
static inline void *coru_malloc(size_t size) {
#ifndef CORU_NO_MALLOC
return malloc(size);
#else
(void)size;
return NULL;
#endif
}
static inline void coru_free(void *p) {
#ifndef CORU_NO_MALLOC
free(p);
#else
(void)p;
#endif
}
#ifdef __cplusplus
}
#endif
#endif
#endif