diff options
author | 2020-02-25 09:57:14 +0200 | |
---|---|---|
committer | 2020-02-25 09:57:14 +0200 | |
commit | ad1bc59382e3cda63ce507cd7f56fc2a201c11e9 (patch) | |
tree | f57c6c7c672eb2e62bc9ba61a9f32265b4abf8a8 /src/io.c | |
parent | 1bcfe887515845678f8f648c6dfecffd01813b0f (diff) | |
download | algos-ld1-ad1bc59382e3cda63ce507cd7f56fc2a201c11e9.tar.gz algos-ld1-ad1bc59382e3cda63ce507cd7f56fc2a201c11e9.tar.bz2 algos-ld1-ad1bc59382e3cda63ce507cd7f56fc2a201c11e9.zip |
implement reading from dev-you-random for datagen.
Signed-off-by: Gediminas Jakutis <gediminas@varciai.lt>
Diffstat (limited to 'src/io.c')
-rw-r--r-- | src/io.c | 23 |
1 files changed, 12 insertions, 11 deletions
@@ -9,24 +9,25 @@ #include <string.h> #include <libgen.h> #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); |