]> git.ozlabs.org Git - ccan/blobdiff - ccan/opt/usage.c
ccanlint: Correct default coverage tool for clang
[ccan] / ccan / opt / usage.c
index 3edc4cf87ade8c8158eed5f01f9500944ae7c264..26150ea8cd409e6c84d5a33067fd15932bccb4dc 100644 (file)
@@ -1,4 +1,4 @@
-/* Licensed under GPLv3+ - see LICENSE file for details */
+/* Licensed under GPLv2+ - see LICENSE file for details */
 #include <ccan/opt/opt.h>
 #if HAVE_SYS_TERMIOS_H
 #include <sys/ioctl.h>
@@ -9,6 +9,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdint.h>
+#include <stdarg.h>
 #include "private.h"
 
 /* We only use this for pointer comparisons. */
@@ -227,3 +228,17 @@ char *opt_usage(const char *argv0, const char *extra)
        ret[len] = '\0';
        return ret;
 }
+
+void opt_usage_exit_fail(const char *msg, ...)
+{
+       va_list ap;
+
+       if (opt_argv0)
+               fprintf(stderr, "%s: ", opt_argv0);
+       va_start(ap, msg);
+       vfprintf(stderr, msg, ap);
+       va_end(ap);
+       fprintf(stderr, "\n%s",
+               opt_usage(opt_argv0 ? opt_argv0 : "<program>", NULL));
+       exit(1);
+}