-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathutil_sys.h
More file actions
52 lines (40 loc) · 1.71 KB
/
Copy pathutil_sys.h
File metadata and controls
52 lines (40 loc) · 1.71 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
#ifndef util_sys_h
#define util_sys_h
typedef uint32_t at_t;
// returns a number that increments in seconds for comparison (epoch or just since boot)
at_t util_sys_seconds();
// number of milliseconds since given epoch seconds value
unsigned long long util_sys_ms(long epoch);
unsigned short util_sys_short(unsigned short x);
unsigned long util_sys_long(unsigned long x);
// use the platform's best RNG
void util_sys_random_init(void);
long util_sys_random(void);
// -1 toggles debug, 0 disable, 1 enable
void util_sys_logging(int enabled);
// returns NULL for convenient return logging
void *util_sys_log(uint8_t level, const char *file, int line, const char *function, const char * format, ...);
// use syslog levels https://en.wikipedia.org/wiki/Syslog#Severity_level
#define LOG_LEVEL(level, fmt, ...) util_sys_log(level, __FILE__, __LINE__, __func__, fmt, ## __VA_ARGS__)
// default LOG is DEBUG level and compile-time optional
#ifndef LOG_DEBUG
#ifdef NOLOG
#define LOG(...) NULL
#define LOG_DEBUG LOG
#define LOG_INFO LOG
#define LOG_WARN LOG
#define LOG_ERROR LOG
#define LOG_CRAZY LOG
#else
#define LOG(fmt, ...) util_sys_log(7, __FILE__, __LINE__, __func__, fmt, ## __VA_ARGS__)
#define LOG_DEBUG LOG
#define LOG_INFO(fmt, ...) util_sys_log(6, __FILE__, __LINE__, __func__, fmt, ## __VA_ARGS__)
#define LOG_WARN(fmt, ...) util_sys_log(4, __FILE__, __LINE__, __func__, fmt, ## __VA_ARGS__)
#define LOG_ERROR(fmt, ...) util_sys_log(3, __FILE__, __LINE__, __func__, fmt, ## __VA_ARGS__)
#define LOG_CRAZY(fmt, ...) util_sys_log(8, __FILE__, __LINE__, __func__, fmt, ## __VA_ARGS__)
#endif
#else
#define LOG(fmt, ...) util_sys_log(7, __FILE__, __LINE__, __func__, fmt, ## __VA_ARGS__)
#endif
// most things just need these
#endif