summaryrefslogtreecommitdiff
path: root/src/set.c
blob: 3c032318a9263ae58f279a9f48b90d2507f4d0aa (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "config.h"

#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "logerr.h"
#include "util.h"

#include "set.h"



struct Set {
	size_t count;
};



int
set_new(const struct Set **const out) {
	int rc = -1;

	const struct Set *ret = NULL;

	ret = malloc(sizeof(*ret));
	if (ret == NULL) {
		logerr("malloc(): %s", strerror(errno));
		goto out;
	}

	memcpy((void *)ret, &(struct Set) {
		.count = 0U,
	}, sizeof(*ret));
	*out = ret;
	rc = 0;
out:
	if (rc) {
		if (ret != NULL) {
			freeit((void *)&ret);
		}
	}
	return rc;
}

void
set_free(const struct Set **const s) {
	assert((*s) != NULL);
	free((void *)*s);
}