diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-04-22 23:27:07 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-04-22 23:31:01 +0200 |
commit | 291803b886fdbe2ff49dd248c19f38b3d7b68524 (patch) | |
tree | b3d6e706fb8eabb7df391ebce3af322b56e2ab23 /lib/errors | |
parent | c62ed622ee5612e155e4176767ab1028f89a3b82 (diff) |
Add usage()
Diffstat (limited to 'lib/errors')
-rw-r--r-- | lib/errors/usage.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/errors/usage.c b/lib/errors/usage.c new file mode 100644 index 0000000..50ca04f --- /dev/null +++ b/lib/errors/usage.c @@ -0,0 +1,26 @@ +#include <stdarg.h> +#include <stdio.h> +#include <string.h> + +#include "errors.h" +#include "macros.h" + +void +(usage)(const char *s, ...) +{ + ASSUME(s != nullptr); + ASSUME(mlib_progname() != nullptr); + + va_list ap; + va_start(ap, s); + + fprintf(stderr, "Usage: %s %s\n", mlib_progname(), s); + + while ((s = va_arg(ap, char *)) != nullptr) { + for (size_t i = 0; i < lengthof("Usage: ") - 1; i++) + fputc(' ', stderr); + fprintf(stderr, "%s %s\n", mlib_progname(), s); + } + + va_end(ap); +} |