-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfail.h
More file actions
52 lines (44 loc) · 1.33 KB
/
fail.h
File metadata and controls
52 lines (44 loc) · 1.33 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 FAIL_H
#define FAIL_H
#include <stdbool.h>
#include <stdlib.h>
#include <execinfo.h>
#include <stdio.h>
#include <stdarg.h>
/**
* @brief The fail-module.
*
* @file fail.h
* @author WingCorp (https://github.com/WingCorp)
* @date 2018-06-19
*/
/**
* @brief Exit the program with an error value.
*/
void fail();
#define FAIL_RED "\x1b[31m"
#define FAIL_RESET "\x1b[0m"
void trace_stack();
#define failwith(message) \
do { \
fprintf(stderr, FAIL_RED); \
fprintf(stderr, message); \
fprintf(stderr, FAIL_RESET); \
trace_stack(); \
exit(EXIT_FAILURE); \
} while (0)
/**
* @brief Print the error cause and exit the program with an error value.
*
* @param cause to print before exiting. Use this like you would use printf.
* @param VAR_ARGS, whatever you want it to say in your failure output.
*/
#define failwithf(format, ...) \
do { \
fprintf(stderr, FAIL_RED); \
fprintf(stderr, format, ##__VA_ARGS__); \
fprintf(stderr, FAIL_RESET); \
trace_stack(); \
exit(EXIT_FAILURE); \
} while(0)
#endif