cdfecb8 |
Jamozed |
2022-03-06 15:11:25 |
0
|
// util/error.h, version 1.1.2 |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
1
|
// Error header file from libutil |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
2
|
// Copyright (C) 2020, Jakob Wakeling |
cdfecb8 |
Jamozed |
2022-03-06 15:11:25 |
3
|
// MIT Licence |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
4
|
|
b181413 |
Jamozed |
2022-02-05 22:32:00 |
5
|
#ifndef UTIL_ERROR_H_38W06M3W |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
6
|
#define UTIL_ERROR_H_38W06M3W |
cdfecb8 |
Jamozed |
2022-03-06 15:11:25 |
7
|
|
cdfecb8 |
Jamozed |
2022-03-06 15:11:25 |
8
|
#ifdef __cplusplus |
cdfecb8 |
Jamozed |
2022-03-06 15:11:25 |
9
|
extern "C" { |
cdfecb8 |
Jamozed |
2022-03-06 15:11:25 |
10
|
#endif |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
11
|
|
b181413 |
Jamozed |
2022-02-05 22:32:00 |
12
|
#include <errno.h> |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
13
|
#include <stdbool.h> |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
14
|
#include <stdnoreturn.h> |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
15
|
#include <string.h> |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
16
|
|
b181413 |
Jamozed |
2022-02-05 22:32:00 |
17
|
/* Warn and then return status */ |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
18
|
#define WARN_R(status, format, ...) do { \ |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
19
|
warn(format, __VA_ARGS__); return status; \ |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
20
|
} while (0) |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
21
|
|
b181413 |
Jamozed |
2022-02-05 22:32:00 |
22
|
/* Warn and then reset errno */ |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
23
|
#define WARN_E(format, ...) do { \ |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
24
|
warn(format, __VA_ARGS__); errno = 0; \ |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
25
|
} while (0) |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
26
|
|
b181413 |
Jamozed |
2022-02-05 22:32:00 |
27
|
/* Warn, reset errno, and then return status */ |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
28
|
#define WARN_RE(status, format, ...) do { \ |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
29
|
warn(format, __VA_ARGS__); errno = 0; return status; \ |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
30
|
} while (0) |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
31
|
|
b181413 |
Jamozed |
2022-02-05 22:32:00 |
32
|
/* Alert and then return status */ |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
33
|
#define ALERT_R(status, format, ...) do { \ |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
34
|
alert(format, __VA_ARGS__); return status; \ |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
35
|
} while (0) |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
36
|
|
b181413 |
Jamozed |
2022-02-05 22:32:00 |
37
|
/* Alert and then reset errno */ |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
38
|
#define ALERT_E(format, ...) do { \ |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
39
|
alert(format, __VA_ARGS__); errno = 0; \ |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
40
|
} while (0) |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
41
|
|
b181413 |
Jamozed |
2022-02-05 22:32:00 |
42
|
/* Alert, reset errno, and then return status */ |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
43
|
#define ALERT_RE(status, format, ...) do { \ |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
44
|
alert(format, __VA_ARGS__); errno = 0; return status; \ |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
45
|
} while (0) |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
46
|
|
b181413 |
Jamozed |
2022-02-05 22:32:00 |
47
|
/* Shorthand for strerror(serrno). */ |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
48
|
#define SERR (strerror(errno)) |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
49
|
|
b181413 |
Jamozed |
2022-02-05 22:32:00 |
50
|
extern char *A0; |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
51
|
extern bool warned; |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
52
|
|
b181413 |
Jamozed |
2022-02-05 22:32:00 |
53
|
/* Print an error message and exit. */ |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
54
|
extern noreturn void error(int status, const char *format, ...); |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
55
|
/* Print a warning message and set the warned flag. */ |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
56
|
extern void warn(const char *format, ...); |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
57
|
/* Print a warning message but do not set the warned flag. */ |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
58
|
extern void alert(const char *format, ...); |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
59
|
|
b181413 |
Jamozed |
2022-02-05 22:32:00 |
60
|
/* Shorthand for strerror(errno). DEPRECIATED, use the SERR macro. */ |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
61
|
extern char *serr(void); |
cdfecb8 |
Jamozed |
2022-03-06 15:11:25 |
62
|
|
cdfecb8 |
Jamozed |
2022-03-06 15:11:25 |
63
|
#ifdef __cplusplus |
cdfecb8 |
Jamozed |
2022-03-06 15:11:25 |
64
|
} // extern "C" |
cdfecb8 |
Jamozed |
2022-03-06 15:11:25 |
65
|
#endif |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
66
|
|
b181413 |
Jamozed |
2022-02-05 22:32:00 |
67
|
#endif // UTIL_ERROR_H_38W06M3W |
|
|
|
68
|
|