cryptutils

Cryptographic Software Utilities
git clone http://git.omkov.net/cryptutils
Log | Tree | Refs | README | LICENCE | Download

cryptutils/src/util/error.h (69 lines, 1.7 KiB) -rw-r--r-- file download

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