-
Notifications
You must be signed in to change notification settings - Fork 0
/
error_c.h
39 lines (31 loc) · 1.38 KB
/
error_c.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
#ifndef __ERROR_H__
#define __ERROR_H__
#include <stdio.h>
#include <stdlib.h>
#define ERROR_LOG_FILE "error_log.txt"
typedef enum {
ERROR_LEVEL_INFO,
ERROR_LEVEL_WARNING,
ERROR_LEVEL_ERROR
} ErrorLevel;
typedef struct {
char *message;
const char *file;
unsigned int line;
ErrorLevel level_c;
} Error;
void error_print(const Error *err);
void error_log(const Error *err);
#define ERROR_C(level, msg) \
do \
{ \
Error err = {.message = msg, .file = __FILE__, .line = __LINE__, .level_c = level}; \
error_print(&err); \
error_log(&err); \
if (level == ERROR_LEVEL_ERROR) \
{ \
exit(EXIT_FAILURE); \
} \
} while (0)
#include "error_c.c"
#endif