-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.h
16 lines (12 loc) · 868 Bytes
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifndef utils_include
#define utils_include 1
#define STRINGIZE_DETAIL(x) #x
#define STRINGIZE(x) STRINGIZE_DETAIL(x)
#define allocfail_return_null(ptr) do {if (ptr == NULL) { perror(__FILE__ ":" STRINGIZE(__LINE__)" alloc failled"); return NULL; }} while(0)
#define allocfail_return(ptr) do {if (ptr == NULL) { perror(__FILE__ ":" STRINGIZE(__LINE__) " alloc failled"); return; }} while(0)
#define allocfail_exit(ptr) do {if (ptr == NULL) { perror(__FILE__ ":" STRINGIZE(__LINE__) " alloc failled"); exit(EXIT_FAILURE); }} while(0)
#define allocfail_print(ptr) do {if (ptr == NULL) { perror(__FILE__ ":" STRINGIZE(__LINE__) " alloc failled"); }} while(0)
#define efree(ptr) do {if (ptr != NULL) { free(ptr); ptr = NULL; }} while(0)
#define estrcmp(a, b) ((a == NULL || b == NULL) ? 0 : strcmp(a, b))
#define estrdup(ptr) (ptr == NULL ? NULL : strdup(ptr))
#endif