summaryrefslogtreecommitdiff
path: root/lib/ccan/err/err.h
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2012-06-09 15:37:20 +0930
committerRusty Russell <rusty@rustcorp.com.au>2012-06-09 15:41:18 +0930
commitd9ce876ea97d59d66c8d2892b43b7cc8392470a0 (patch)
tree9b75e61a0b9ab13ee598369d4e59abcba5d4e29b /lib/ccan/err/err.h
parent8a338c65a1824ae8a93bef7bc8fac65684c285c8 (diff)
downloadsamba-d9ce876ea97d59d66c8d2892b43b7cc8392470a0.tar.gz
samba-d9ce876ea97d59d66c8d2892b43b7cc8392470a0.tar.bz2
samba-d9ce876ea97d59d66c8d2892b43b7cc8392470a0.zip
ccan: import err module.from ccan revision 5add556a1cb64b49a664506aa76216d885b22c97
This allows us to avoid err.h in failtest. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib/ccan/err/err.h')
-rw-r--r--lib/ccan/err/err.h87
1 files changed, 87 insertions, 0 deletions
diff --git a/lib/ccan/err/err.h b/lib/ccan/err/err.h
new file mode 100644
index 0000000000..58ad91c728
--- /dev/null
+++ b/lib/ccan/err/err.h
@@ -0,0 +1,87 @@
+#ifndef CCAN_ERR_H
+#define CCAN_ERR_H
+#include "config.h"
+
+#if HAVE_ERR_H
+#include <err.h>
+
+/* This is unnecessary with a real err.h. See below */
+#define err_set_progname(name) ((void)name)
+
+#else
+#include <ccan/compiler/compiler.h>
+
+/**
+ * err_set_progname - set the program name
+ * @name: the name to use for err, errx, warn and warnx
+ *
+ * The BSD err.h calls know the program name, unfortunately there's no
+ * portable way for the CCAN replacements to do that on other systems.
+ *
+ * If you don't call this with argv[0], it will be "unknown program".
+ *
+ * Example:
+ * err_set_progname(argv[0]);
+ */
+void err_set_progname(const char *name);
+
+/**
+ * err - exit(eval) with message based on format and errno.
+ * @eval: the exit code
+ * @fmt: the printf-style format string
+ *
+ * The format string is printed to stderr like so:
+ * <executable name>: <format>: <strerror(errno)>\n
+ *
+ * Example:
+ * char *p = strdup("hello");
+ * if (!p)
+ * err(1, "Failed to strdup 'hello'");
+ */
+void NORETURN err(int eval, const char *fmt, ...);
+
+/**
+ * errx - exit(eval) with message based on format.
+ * @eval: the exit code
+ * @fmt: the printf-style format string
+ *
+ * The format string is printed to stderr like so:
+ * <executable name>: <format>\n
+ *
+ * Example:
+ * if (argc != 1)
+ * errx(1, "I don't expect any arguments");
+ */
+void NORETURN errx(int eval, const char *fmt, ...);
+
+/**
+ * warn - print a message to stderr based on format and errno.
+ * @eval: the exit code
+ * @fmt: the printf-style format string
+ *
+ * The format string is printed to stderr like so:
+ * <executable name>: <format>: <strerror(errno)>\n
+ *
+ * Example:
+ * char *p = strdup("hello");
+ * if (!p)
+ * warn("Failed to strdup 'hello'");
+ */
+void warn(const char *fmt, ...);
+
+/**
+ * warnx - print a message to stderr based on format.
+ * @eval: the exit code
+ * @fmt: the printf-style format string
+ *
+ * The format string is printed to stderr like so:
+ * <executable name>: <format>\n
+ *
+ * Example:
+ * if (argc != 1)
+ * warnx("I don't expect any arguments (ignoring)");
+ */
+void warnx(const char *fmt, ...);
+#endif
+
+#endif /* CCAN_ERR_H */