summaryrefslogtreecommitdiffstats
path: root/src/datagen.c
blob: 98a64fe5588d80a71314627c2d390970b2e7fbde (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
35
36
37
38
39
40
/* SPDX-License-Identifier: LGPL-2.1-only */

/* Copyright (C) 2020 Gediminas Jakutis */

#include <errno.h>
#include <string.h>
#include <sys/random.h>
#include "datagen.h"
#include "defs.h"

static struct entry_l buf;

struct entry_l *gen_get_array(struct stream * const in)
{
	struct entry_l *ret;
	int errn;

	(void) in; /* lol says librin, lmao */

	if (getrandom(&buf.val, sizeof(buf.val), 0ul) == sizeof(buf.val)) {
		ret = &buf;
	} else {
		errn = errno;
		ret = NULL;
		rin_err("error reading urandom: %s", strerror(errn));
	}

	return ret;
}

struct entry_l *gen_get_list(struct stream * const in)
{
	struct entry_l *ret;

	try_s((ret = gen_get_array(in)), err);
	ret->next = 0;

err:
	return ret;
}