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