Merge branch 'vendor/LIBRESSL'
[dragonfly.git] / crypto / libressl / include / compat / err.h
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 <stdarg.h>
17 #include <stdlib.h>
18 #include <stdio.h>
19 #include <string.h>
20
21 static inline void
22 err(int eval, const char *fmt, ...)
23 {
24         int sverrno = errno;
25         va_list ap;
26
27         va_start(ap, fmt);
28         if (fmt != NULL) {
29                 vfprintf(stderr, fmt, ap);
30                 fprintf(stderr, ": ");
31         }
32         fprintf(stderr, "%s\n", strerror(sverrno));
33         exit(eval);
34         va_end(ap);
35 }
36
37 static inline void
38 errx(int eval, const char *fmt, ...)
39 {
40         va_list ap;
41
42         va_start(ap, fmt);
43         if (fmt != NULL)
44                 vfprintf(stderr, fmt, ap);
45         fprintf(stderr, "\n");
46         exit(eval);
47         va_end(ap);
48 }
49
50 static inline void
51 warn(const char *fmt, ...)
52 {
53         int sverrno = errno;
54         va_list ap;
55
56         va_start(ap, fmt);
57         if (fmt != NULL) {
58                 vfprintf(stderr, fmt, ap);
59                 fprintf(stderr, ": ");
60         }
61         fprintf(stderr, "%s\n", strerror(sverrno));
62         va_end(ap);
63 }
64
65 static inline void
66 warnx(const char *fmt, ...)
67 {
68         va_list ap;
69
70         va_start(ap, fmt);
71         if (fmt != NULL)
72                 vfprintf(stderr, fmt, ap);
73         fprintf(stderr, "\n");
74         va_end(ap);
75 }
76
77 #endif
78
79 #endif