]> git.draconx.ca Git - liblbx.git/blobdiff - src/tools.h
tools: Add some smarter error printing routines.
[liblbx.git] / src / tools.h
index 315d9654fbe5ddbcc368833a834284f18e769dee..c2c10fff40d77f59666a4023682e2a621f7d6d18 100644 (file)
 #ifndef TOOLS_H_
 #define TOOLS_H_
 
+#include <stdarg.h>
+
 void tool_init(const char *name, int argc, char **argv);
 void tool_version(void);
 
 const char *tool_invocation(void);
 
-#define errmsg(fmt, ...) (\
-       fprintf(stderr, "%s: " fmt, tool_invocation(), __VA_ARGS__)\
-)
+/*
+ * Error messaging routines.  Similar to printf, but writes to standard error
+ * and prefixes the output with the program invocation name, automatically
+ * appending a newline.  If err is 0, the result of strerror(errno) is also
+ * printed in a similar manner as perror.  If err is positive, then that
+ * value is used instead of errno.
+ */
+int tool_verr(int err, const char *fmt, va_list ap);
+int tool_err(int err, const char *fmt, ...);
+
+/*
+ * Messaging routines similar to the above, except that they write to standard
+ * output and there is no option to include strerror(errno).
+ */
+int tool_vmsg(const char *fmt, va_list ap);
+int tool_msg(const char *fmt, ...);
 
 #endif