diff options
Diffstat (limited to 'src/io.c')
-rw-r--r-- | src/io.c | 45 |
1 files changed, 32 insertions, 13 deletions
@@ -17,8 +17,9 @@ #include "datagen.h" #include "cache.h" -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_out_lite(struct stream * const in, const struct settings * const s); +static int stream_open_in(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, const struct settings * const s) @@ -27,9 +28,13 @@ int stream_open(struct stream * const in, const struct settings * const s) try(!in || in->fd > 0 || !in->name || !s, err, EINVAL, "invalid argunent"); - if (in->out == 1) { + if (in->out == 2) { + ret = stream_open_out_lite(in, s); + } else if (in->out == 1) { + try(!in->name, err, EINVAL, "no filename given"); ret = stream_open_out(in, s); } else if (!in->out) { + try(!in->name, err, EINVAL, "no filename given"); ret = stream_open_in(in, s); } else { ret = stream_open_special(in); @@ -101,7 +106,31 @@ static int stream_open_out(struct stream * const in, const struct settings * con mode = st.st_mode; } - in->fd = open(dname, O_TMPFILE | O_WRONLY, mode); + in->fd = open(dname, O_TMPFILE | O_RDWR, mode); + try(in->fd < 0, err, errno, "failed creating temporary output file: %s", strerror(ret)); + try(ftruncate(in->fd, s->stride * in->n), err, errno, "failed setting output file size: %s", strerror(ret)); + +err: + free(dname); + return ret; +} + +static int stream_open_out_lite(struct stream * const in, const struct settings * const s) +{ + struct stat st; + char *dname = NULL; + char *tmp[2]; + int ret = 0; + + tmp[0] = strdup(in->name); + tmp[1] = dirname(tmp[0]); + dname = strdup(tmp[1]); + free(tmp[0]); + + try(stat(dname, &st), err, errno, "stat failed: %s", strerror(ret)); + try(!(st.st_mode & S_IFDIR), err, EINVAL, "invalid output path"); + + in->fd = open(dname, O_TMPFILE | O_RDWR, S_IRUSR | S_IWUSR); try(in->fd < 0, err, errno, "failed creating temporary output file: %s", strerror(ret)); try(ftruncate(in->fd, s->stride * in->n), err, errno, "failed setting output file size: %s", strerror(ret)); @@ -120,10 +149,6 @@ static int stream_open_in(struct stream * const in, const struct settings * cons in->n = st.st_size / s->stride; in->fd = open(in->name, O_RDONLY | O_NOATIME); try(in->fd < 0, err, errno, "failed opening input file: %s", strerror(ret)); - if (in->cached) { - cache_create(in, s); - cache_populate(in); - } err: return ret; @@ -141,9 +166,3 @@ static int stream_open_special(struct stream * const in) err: return ret; } - -int direct_get_array(struct stream * const restrict in, ssize_t idx, struct entry_l * const data); -int direct_get_list(struct stream * const restrict in, ssize_t idx, struct entry_l * const data); - -int direct_put_array(struct stream * const restrict in, ssize_t idx, const struct entry_l * const data); -int direct_put_list(struct stream * const restrict in, ssize_t idx, const struct entry_l * const data); |