aboutsummaryrefslogtreecommitdiff
path: root/lib/errors/usage.c
blob: 50ca04f3bbf30f401a343a7f07c1ea7921a34396 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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);
}