forked from kitsunyan/intel-undervolt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.h
61 lines (49 loc) · 1.49 KB
/
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
#ifndef __UTIL_H__
#define __UTIL_H__
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#if defined(__GNUC__)
#define UNUSED __attribute__((unused))
#else
#define UNUSED
#endif
#if defined(__GNUC__) && __GNUC__ >= 7
#define BEGIN_IGNORE_FORMAT_OVERFLOW \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wformat-overflow\"")
#define END_IGNORE_FORMAT_OVERFLOW \
_Pragma("GCC diagnostic pop")
#else
#define BEGIN_IGNORE_FORMAT_OVERFLOW
#define END_IGNORE_FORMAT_OVERFLOW
#endif
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
#define IS_FREEBSD
#endif
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#define GLOBAL_LOCAL_SEPARATOR(global, local, separator, always) { \
if (global != NULL) { \
if (*(global) && !(local)) { \
printf(separator); \
} \
if (*(global) && always) { \
printf(separator); \
} \
*(global) = true; \
(local) = true; \
} \
}
#define NEW_LINE(global, local) GLOBAL_LOCAL_SEPARATOR(global, local, "\n", false)
#define CSV_SEPARATOR(global, local) GLOBAL_LOCAL_SEPARATOR(global, local, ";", true)
bool strn_eq_const(const char * str, const char * cstr, size_t n);
bool safe_rw(uint64_t * addr, uint64_t * data, bool write);
struct array_t {
int count;
};
struct array_t * array_new(int item_size, void (* item_free)(void *));
void * array_get(struct array_t * array, int index);
void * array_add(struct array_t * array);
bool array_shrink(struct array_t * array);
void array_free(struct array_t * array);
#endif