diff options
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); |