summaryrefslogtreecommitdiffstats
path: root/src/datagen.c
diff options
context:
space:
mode:
authorGravatar Gediminas Jakutis <gediminas@varciai.lt> 2021-02-09 05:43:36 +0200
committerGravatar Gediminas Jakutis <gediminas@varciai.lt> 2021-02-09 05:43:36 +0200
commit41efe7b8f9f67d5956ab677f3631478c48114ac1 (patch)
tree9b2d1cff2bc30b484a9192a498d38344803d83d9 /src/datagen.c
parent7754455c48c50764ad7291ea508109c53b60517f (diff)
downloadalgos-ld1-41efe7b8f9f67d5956ab677f3631478c48114ac1.tar.gz
algos-ld1-41efe7b8f9f67d5956ab677f3631478c48114ac1.tar.bz2
algos-ld1-41efe7b8f9f67d5956ab677f3631478c48114ac1.zip
A major overhaul of the whole thing.
It has come to my attention that previously, the project was built on top of some *very* incorrect assumptions. This patch mostly addresses that. And while it does NOT leave the project in otherwise working state, it does weed out most, if not all, of effects of previously incorrect assumptions, so it can be built the right way from here on forth. Signed-off-by: Gediminas Jakutis <gediminas@varciai.lt>
Diffstat (limited to 'src/datagen.c')
-rw-r--r--src/datagen.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/src/datagen.c b/src/datagen.c
index 25002e2..7eab23f 100644
--- a/src/datagen.c
+++ b/src/datagen.c
@@ -6,37 +6,36 @@
#include <stddef.h>
#include <errno.h>
#include <stdlib.h>
+#include <string.h>
#include <sys/types.h>
#include "datagen.h"
#include "defs.h"
-int gen_get_array(struct stream * const in, ssize_t idx, struct entry_l * const data)
-{
- int ret = 0;
- (void) idx;
+static struct entry_l buf;
- in->prev_idx = -1;
- ret = read(in->fd, &data->val, sizeof(data->val));
+struct entry_l *gen_get_array(struct stream * const in)
+{
+ struct entry_l *ret;
+ int errn;
- if (ret != sizeof(data->val)) {
- ret = ret > 0 ? EAGAIN : errno;
+ if (read(in->fd, &buf.val, sizeof(buf.val)) == sizeof(buf.val)) {
+ ret = &buf;
+ } else {
+ errn = errno;
+ ret = NULL;
+ rin_err("error reading /dev/urandom: %s", strerror(errn));
}
return ret;
}
-int gen_get_list(struct stream * const restrict in, ssize_t idx, struct entry_l * const data)
+struct entry_l *gen_get_list(struct stream * const in)
{
- int ret = 0;
+ struct entry_l *ret;
- 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);
- }
+ try_s((ret = gen_get_array(in)), err);
+ ret->next = 0;
+err:
return ret;
}