summaryrefslogtreecommitdiffstats
path: root/src/datagen.c
blob: d4c8bab9f5d8d3612f1d924093730c1039c355fb (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
41
42
43
44
45
46
47
/* SPDX-License-Identifier: LGPL-2.1-only */

/* Copyright (C) 2020 Gediminas Jakutis */

#include <unistd.h>
#include <stddef.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/types.h>
#include "datagen.h"
#include "defs.h"

int gen_get_array(struct stream * const restrict in, ssize_t idx, struct entry_l * const data)
{
	int ret = 0;
	(void) idx;

	in->prev_idx = -1;
	ret = read(in->fd, &data->val, sizeof(data->val));

	if (ret != sizeof(data->val)) {
		ret = ret > 0 ? EAGAIN : errno;
	}

	return ret;
}

int gen_get_list(struct stream * const restrict in, ssize_t idx, struct entry_l * const data)
{
	int ret = 0;

	data->prev = idx > 0 ? idx - 1 : labs(idx) - 1;
	data->next = idx + 1;

	if (!idx) {
		data->val = 0; /* header lmao */
	} else {
		ret = gen_get_array(in, idx, data);
	}

	return ret;
}

int gen_put(struct stream * const restrict in, ssize_t idx, const struct entry_l * const data)
{
	return ENOSYS;
}