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