summaryrefslogtreecommitdiffstats
path: root/src/test.c
blob: 40e18282dfa8ce60ad2f106c3fbad63a9e57047b (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
27
28
29
30
31
32
#include "strvec.h"
#include "allocator.h"

#include <err.h>
#include <string.h>
#include <stdio.h>

#define LIBSTRVEC_ERR(rc) errx(1, "libstrvec: %s", strerror(-rc))

int
main(int argc, const char **argv)
{
	struct strvec *strvec;
	const char **arg;

	strvec = strvec_alloc(0, &stdlib_strict_heap_allocator, NULL);

	if (!argc) return 1;
	for (arg = &argv[1]; *arg; arg++) {
		strvec_push(strvec, *arg);
	}

	strvec_push(strvec, "--");
	strvec_push(strvec, "end");
	strvec_push(strvec, NULL);

	for (arg = strvec_stra(strvec); *arg; arg++) {
		printf("%s\n", *arg);
	}

	strvec_free(strvec);
}