]> git.ozlabs.org Git - ccan/blob - ccan/err/err.h
ccan/err: new err.h-replacing module.
[ccan] / ccan / err / err.h
1 #ifndef CCAN_ERR_H
2 #define CCAN_ERR_H
3 #include "config.h"
4
5 #if HAVE_ERR_H
6 #include <err.h>
7 #else
8 #include <ccan/compiler/compiler.h>
9
10 /**
11  * err - exit(eval) with message based on format and errno.
12  * @eval: the exit code
13  * @fmt: the printf-style format string
14  *
15  * The format string is printed to stderr like so:
16  *      <executable name>: <format>: <strerror(errno)>\n
17  *
18  * Example:
19  *      char *p = strdup("hello");
20  *      if (!p)
21  *              err(1, "Failed to strdup 'hello'");
22  */
23 void NORETURN err(int eval, const char *fmt, ...);
24
25 /**
26  * errx - exit(eval) with message based on format.
27  * @eval: the exit code
28  * @fmt: the printf-style format string
29  *
30  * The format string is printed to stderr like so:
31  *      <executable name>: <format>\n
32  *
33  * Example:
34  *      if (argc != 1)
35  *              errx(1, "I don't expect any arguments");
36  */
37 void NORETURN errx(int eval, const char *fmt, ...);
38
39 /**
40  * warn - print a message to stderr based on format and errno.
41  * @eval: the exit code
42  * @fmt: the printf-style format string
43  *
44  * The format string is printed to stderr like so:
45  *      <executable name>: <format>: <strerror(errno)>\n
46  *
47  * Example:
48  *      char *p = strdup("hello");
49  *      if (!p)
50  *              warn("Failed to strdup 'hello'");
51  */
52 void warn(const char *fmt, ...);
53
54 /**
55  * warnx - print a message to stderr based on format.
56  * @eval: the exit code
57  * @fmt: the printf-style format string
58  *
59  * The format string is printed to stderr like so:
60  *      <executable name>: <format>\n
61  *
62  * Example:
63  *      if (argc != 1)
64  *              warnx("I don't expect any arguments (ignoring)");
65  */
66 void warnx(const char *fmt, ...);
67 #endif
68
69 #endif /* CCAN_ERR_H */