From ad1bc59382e3cda63ce507cd7f56fc2a201c11e9 Mon Sep 17 00:00:00 2001 From: Gediminas Jakutis Date: Tue, 25 Feb 2020 09:57:14 +0200 Subject: implement reading from dev-you-random for datagen. Signed-off-by: Gediminas Jakutis --- src/io.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'src/io.c') diff --git a/src/io.c b/src/io.c index f10269c..edcda17 100644 --- a/src/io.c +++ b/src/io.c @@ -9,24 +9,25 @@ #include #include #include "io.h" +#include "defs.h" -static int stream_open_in(struct stream * const in); -static int stream_open_out(struct stream * const in); +static int stream_open_in(struct stream * const in, const struct settings * const s); +static int stream_open_out(struct stream * const in, const struct settings * const s); static int stream_open_special(struct stream * const in); -int stream_open(struct stream * const in) +int stream_open(struct stream * const in, const struct settings * const s) { int ret = 0; - if (!in || in->fd > 0 || !in->name) { + if (!in || in->fd > 0 || !in->name || !s) { ret = EINVAL; goto err; } if (in->out == 1) { - ret = stream_open_out(in); + ret = stream_open_out(in, s); } else if (!in->out) { - ret = stream_open_in(in); + ret = stream_open_in(in, s); } else { ret = stream_open_special(in); } @@ -82,7 +83,7 @@ early_err: return ret; } -static int stream_open_out(struct stream * const in) +static int stream_open_out(struct stream * const in, const struct settings * const s) { struct stat st; mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP; @@ -124,7 +125,7 @@ static int stream_open_out(struct stream * const in) goto err; } - if (ftruncate(in->fd, in->stride * in->n)) { + if (ftruncate(in->fd, s->stride * in->n)) { ret = errno; /* TODO: error message */ goto err; @@ -135,7 +136,7 @@ err: return ret; } -static int stream_open_in(struct stream * const in) +static int stream_open_in(struct stream * const in, const struct settings * const s) { struct stat st; int ret = 0; @@ -144,12 +145,12 @@ static int stream_open_in(struct stream * const in) ret = errno; /* TODO: error message */ goto err; - } else if (!(st.st_mode & S_IFREG) || !st.st_size || (st.st_size % in->stride)) { + } else if (!(st.st_mode & S_IFREG) || !st.st_size || (st.st_size % s->stride)) { ret = EINVAL; /* TODO: error message */ goto err; } else { - in->n = st.st_size / in->stride; + in->n = st.st_size / s->stride; } in->fd = open(in->name, O_RDONLY | O_NOATIME); -- cgit v1.2.3