diff options
author | 2021-03-03 14:57:28 +0200 | |
---|---|---|
committer | 2021-03-03 14:57:28 +0200 | |
commit | 068e3e6c5a74702c3e7db0e37b243f522c433a7f (patch) | |
tree | f786f107ff5759084e3c1f76f5734cad2084fdd2 /src/stream.c | |
parent | b3072e146b4edd4a2422cee758aa341b0638491d (diff) | |
download | algos-ld1-068e3e6c5a74702c3e7db0e37b243f522c433a7f.tar.gz algos-ld1-068e3e6c5a74702c3e7db0e37b243f522c433a7f.tar.bz2 algos-ld1-068e3e6c5a74702c3e7db0e37b243f522c433a7f.zip |
straight up code refactor.
Signed-off-by: Gediminas Jakutis <gediminas@varciai.lt>
Diffstat (limited to 'src/stream.c')
-rw-r--r-- | src/stream.c | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/src/stream.c b/src/stream.c index e29d17d..83235a5 100644 --- a/src/stream.c +++ b/src/stream.c @@ -18,7 +18,7 @@ #include "cache.h" static int stream_open_out(struct stream * const in); -static int stream_open_out_lite(struct stream * const in); +static int stream_open_lite(struct stream * const in); static int stream_open_in(struct stream * const in); static int stream_flush(struct stream * const in); static int stream_flush_array(struct stream * const in); @@ -31,8 +31,8 @@ int stream_open(struct stream * const in) try(!in || in->fd > 0 || (!in->name && in->type != stream_randread), err, EINVAL, "invalid argunent"); switch (in->type) { - case (stream_outlite): - ret = stream_open_out_lite(in); + case (stream_lite): + ret = stream_open_lite(in); break; case (stream_out): try(!in->name, err, EINVAL, "no filename given"); @@ -104,17 +104,15 @@ int stream_shallow_copy(struct stream const * const restrict src, struct stream dest->settings = src->settings; dest->index = 0; - if (src->settings->access == cached) { - dest->type = stream_cache; - dest->get_next_element_cache = src->get_next_element_cache; - dest->place_next_element_cache = src->place_next_element_cache; - dest->split = src->split; - dest->rewind = src->rewind; - try_s((ret = cache_create(dest)), err); - } else { - rin_warn("stub!"); - ret = ENOSYS; - } + dest->get = src->get; + dest->put = src->put; + dest->split = src->split; + dest->rewind = src->rewind; + dest->copy = src->copy; + + dest->type = src->settings->access == cached ? stream_cache : stream_lite; + + try_s((ret = cache_create(dest)), err); err: return ret; @@ -150,7 +148,7 @@ err: return ret; } -static int stream_open_out_lite(struct stream * const in) +static int stream_open_lite(struct stream * const in) { struct stat st; char *dname = NULL; |