diff options
Diffstat (limited to 'src/io.c')
-rw-r--r-- | src/io.c | 29 |
1 files changed, 15 insertions, 14 deletions
@@ -25,7 +25,7 @@ int stream_open(struct stream * const in, const struct settings * const s) { int ret = 0; - try(!in || in->fd > 0 || !in->name || !s, err, EINVAL); + try(!in || in->fd > 0 || !in->name || !s, err, EINVAL, "invalid argunent"); if (in->out == 1) { ret = stream_open_out(in, s); @@ -43,7 +43,7 @@ int stream_close(struct stream * const in) { int ret = 0; - try(!in || in->fd < 0, early_err, EINVAL); + try(!in || in->fd < 0, early_err, EINVAL, "invalid argunent"); if (!in->out) { goto out; @@ -60,13 +60,14 @@ int stream_close(struct stream * const in) unlink(in->name); } else { ret = EINVAL; - /* TODO: error message */ + rin_err("the given output file already exists and is not a regular file"); goto err; } } - try(linkat(AT_FDCWD, path, AT_FDCWD, in->name, AT_SYMLINK_FOLLOW), err, errno); + try(linkat(AT_FDCWD, path, AT_FDCWD, in->name, AT_SYMLINK_FOLLOW), err, errno, "error linking output file to filesystem: %s", strerror(ret)); } else { + rin_err("no output filename given"); ret = EINVAL; goto err; } @@ -92,17 +93,17 @@ static int stream_open_out(struct stream * const in, const struct settings * con dname = strdup(tmp[1]); free(tmp[0]); - try(stat(dname, &st), err, errno); - try(!(st.st_mode & S_IFDIR), err, EINVAL); /* TODO: err msg */ + try(stat(dname, &st), err, errno, "stat failed: %s", strerror(ret)); + try(!(st.st_mode & S_IFDIR), err, EINVAL, "invalid output path"); if (!stat(in->name, &st)) { - try(!(st.st_mode & S_IFREG), err, EINVAL); /* TODO: err msg */ + try(!(st.st_mode & S_IFREG), err, EINVAL, "the given output file already exists and is not a regular file"); mode = st.st_mode; } in->fd = open(dname, O_TMPFILE | O_WRONLY, mode); - try(in->fd < 0, err, errno); /* TODO: err msg */ - try(ftruncate(in->fd, s->stride * in->n), err, errno); /* TODO: err msg */ + 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); @@ -114,11 +115,11 @@ static int stream_open_in(struct stream * const in, const struct settings * cons struct stat st; int ret = 0; - try(stat(in->name, &st), err, errno); /* TODO: err msg */ - try(!(st.st_mode & S_IFREG) || !st.st_size || (st.st_size % s->stride), err, EINVAL); /* TODO: err msg */ + try(stat(in->name, &st), err, errno, "stat failed: %s", strerror(ret)); + try(!(st.st_mode & S_IFREG) || !st.st_size || (st.st_size % s->stride), err, EINVAL, "invalid input file"); in->n = st.st_size / s->stride; in->fd = open(in->name, O_RDONLY | O_NOATIME); - try(in->fd < 0, err, errno); /* TODO: err msg */ + try(in->fd < 0, err, errno, "failed opening input file: %s", strerror(ret)); if (in->cached) { cache_create(in, s); cache_populate(in); @@ -133,9 +134,9 @@ static int stream_open_special(struct stream * const in) struct stat st; int ret = 0; - try(stat(in->name, &st), err, errno); /* TODO: err msg */ + try(stat(in->name, &st), err, errno, "stat failed: %s", strerror(ret)); in->fd = open(in->name, O_RDONLY | O_NOATIME); - try(in->fd < 0, err, errno); /* TODO: err msg */ + try(in->fd < 0, err, errno, "failed opening input file: %s", strerror(ret)); err: return ret; |