]> git.ozlabs.org Git - ccan/blob - ccan/err/err.h
err: actually implement replacement versions!
[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
8 /* This is unnecessary with a real err.h.  See below */
9 #define err_set_progname(name) ((void)name)
10
11 #else
12 #include <ccan/compiler/compiler.h>
13
14 /**
15  * err_set_progname - set the program name
16  * @name: the name to use for err, errx, warn and warnx
17  *
18  * The BSD err.h calls know the program name, unfortunately there's no
19  * portable way for the CCAN replacements to do that on other systems.
20  *
21  * If you don't call this with argv[0], it will be "unknown program".
22  *
23  * Example:
24  *      err_set_progname(argv[0]);
25  */
26 void err_set_progname(const char *name);
27
28 /**
29  * err - exit(eval) with message based on format and errno.
30  * @eval: the exit code
31  * @fmt: the printf-style format string
32  *
33  * The format string is printed to stderr like so:
34  *      <executable name>: <format>: <strerror(errno)>\n
35  *
36  * Example:
37  *      char *p = strdup("hello");
38  *      if (!p)
39  *              err(1, "Failed to strdup 'hello'");
40  */
41 void NORETURN err(int eval, const char *fmt, ...);
42
43 /**
44  * errx - exit(eval) with message based on format.
45  * @eval: the exit code
46  * @fmt: the printf-style format string
47  *
48  * The format string is printed to stderr like so:
49  *      <executable name>: <format>\n
50  *
51  * Example:
52  *      if (argc != 1)
53  *              errx(1, "I don't expect any arguments");
54  */
55 void NORETURN errx(int eval, const char *fmt, ...);
56
57 /**
58  * warn - print a message to stderr based on format and errno.
59  * @eval: the exit code
60  * @fmt: the printf-style format string
61  *
62  * The format string is printed to stderr like so:
63  *      <executable name>: <format>: <strerror(errno)>\n
64  *
65  * Example:
66  *      char *p = strdup("hello");
67  *      if (!p)
68  *              warn("Failed to strdup 'hello'");
69  */
70 void warn(const char *fmt, ...);
71
72 /**
73  * warnx - print a message to stderr based on format.
74  * @eval: the exit code
75  * @fmt: the printf-style format string
76  *
77  * The format string is printed to stderr like so:
78  *      <executable name>: <format>\n
79  *
80  * Example:
81  *      if (argc != 1)
82  *              warnx("I don't expect any arguments (ignoring)");
83  */
84 void warnx(const char *fmt, ...);
85 #endif
86
87 #endif /* CCAN_ERR_H */