From 068e3e6c5a74702c3e7db0e37b243f522c433a7f Mon Sep 17 00:00:00 2001 From: Gediminas Jakutis Date: Wed, 3 Mar 2021 14:57:28 +0200 Subject: straight up code refactor. Signed-off-by: Gediminas Jakutis --- src/stream.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'src/stream.c') 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; -- cgit v1.2.3