aboutsummaryrefslogtreecommitdiff
path: root/src/exhaustive/check.c
blob: 1549af8e8a67bc8112dbb3b1fece0958272b57ba (plain)
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
33
34
/*
 * ecgen, tool for generating Elliptic curve domain parameters
 * Copyright (C) 2017 J08nY
 */
#include "check.h"
#include "util/memory.h"

check_t *check_new(check_f one, ...) {
	check_t *result = try_calloc(sizeof(check_t));
	result->checks = try_calloc(sizeof(check_f));
	result->checks[0] = one;
	result->nchecks = 1;

	va_list args;
	va_start(args, one);
	check_f check;
	while ((check = va_arg(args, check_f)) != NULL) {
		result->checks = try_realloc(result->checks, ++result->nchecks);
		result->checks[result->nchecks - 1] = check;
	}
	va_end(args);

	return result;
}

void check_free(check_t **check) {
	if (*check) {
		if ((*check)->checks) {
			try_free((*check)->checks);
		}
		try_free(*check);
		*check = NULL;
	}
}