-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.h
45 lines (35 loc) · 1.1 KB
/
types.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
#ifndef STACK_TYPES_H_
#define STACK_TYPES_H_
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <libgen.h>
#include "log.h"
#define MAX_ERROR_BUFFER_SIZE 512
#define GLOBAL
#define LIKELY(con) (__builtin_expect(!!(con), 1))
#define UNLIKELY(con) (__builtin_expect(!!(con), 0))
//log
#ifndef CO_DEBUG
#define DBG_LOG //
#else
#define DBG_LOG(fmt, ...) LOG_OUTPUT(LOG_FD_STDOUT, LOG_DEBUG, fmt, ##__VA_ARGS__)
#endif
#define INF_LOG(fmt, ...) LOG_OUTPUT(LOG_FD_STDOUT, LOG_INFO, fmt, ##__VA_ARGS__)
#define ERR_LOG(fmt, ...) LOG_OUTPUT(LOG_FD_STDERR, LOG_ERROR, fmt, ##__VA_ARGS__)
#define dperror(ret) do {\
char _error_buffer[MAX_ERROR_BUFFER_SIZE] = {0};\
strerror_r(errno, _error_buffer, MAX_ERROR_BUFFER_SIZE);\
ERR_LOG("return value: %d, errno: %d, %s", ret, errno, _error_buffer);\
}while(0)
#define dfatal(ret) do{\
dperror(ret);\
exit(-1);\
}while(0)
#define PANIC(string) do {\
ERR_LOG("[PANIC] message: \"%s\"", string);\
exit(-1);\
}while(0)
#define MY_ASSERT(cond, comment) do { if(UNLIKELY(!(cond))) { PANIC(comment); } } while(0)
#endif