diff options
Diffstat (limited to 'include/compat/err.h')
-rw-r--r-- | include/compat/err.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/include/compat/err.h b/include/compat/err.h new file mode 100644 index 0000000..af68a26 --- /dev/null +++ b/include/compat/err.h | |||
@@ -0,0 +1,33 @@ | |||
1 | /* | ||
2 | * Public domain | ||
3 | * err.h compatibility shim | ||
4 | */ | ||
5 | |||
6 | #ifdef HAVE_ERR_H | ||
7 | |||
8 | #include_next <err.h> | ||
9 | |||
10 | #else | ||
11 | |||
12 | #ifndef LIBCRYPTOCOMPAT_ERR_H | ||
13 | #define LIBCRYPTOCOMPAT_ERR_H | ||
14 | |||
15 | #include <errno.h> | ||
16 | #include <stdio.h> | ||
17 | #include <string.h> | ||
18 | |||
19 | #define err(exitcode, format, ...) \ | ||
20 | errx(exitcode, format ": %s", __VA_ARGS__, strerror(errno)) | ||
21 | |||
22 | #define errx(exitcode, format, ...) \ | ||
23 | do { warnx(format, __VA_ARGS__); exit(exitcode); } while (0) | ||
24 | |||
25 | #define warn(format, ...) \ | ||
26 | warnx(format ": %s", __VA_ARGS__, strerror(errno)) | ||
27 | |||
28 | #define warnx(format, ...) \ | ||
29 | fprintf(stderr, format "\n", __VA_ARGS__) | ||
30 | |||
31 | #endif | ||
32 | |||
33 | #endif | ||