diff options
author | 2021-02-15 09:18:31 +0200 | |
---|---|---|
committer | 2021-02-15 09:18:31 +0200 | |
commit | fb383b792d1044405188e42c4b827858c4a3a038 (patch) | |
tree | 706761232471d5e85d31daba26524db150544cd8 /src/io.c | |
parent | 4a14ab7ab48e3fd591dde33d59c6d29fc39f1c5d (diff) | |
download | algos-ld1-fb383b792d1044405188e42c4b827858c4a3a038.tar.gz algos-ld1-fb383b792d1044405188e42c4b827858c4a3a038.tar.bz2 algos-ld1-fb383b792d1044405188e42c4b827858c4a3a038.zip |
now with generating lists!
Signed-off-by: Gediminas Jakutis <gediminas@varciai.lt>
Diffstat (limited to 'src/io.c')
-rw-r--r-- | src/io.c | 30 |
1 files changed, 27 insertions, 3 deletions
@@ -218,11 +218,35 @@ err: int stream_flush_list(struct stream * const in) { - int ret = ENOSYS; + ssize_t ret = 0; + size_t remaining; + ssize_t written; + size_t i; + + /* adjust pointers to have a base starting at 0, to cater to disk storage format. + * File offsets are otherwise 1:1 to memory addresses, which is neat. + * Just don't process the last offset, as that is always NULL/zero. + * */ - (void) in; + for (i = 0; i < (in->n - 1); ++i) { + in->cache_l[i].offset = (char *) in->cache_l[i].next - in->cache; + } - rin_warn("stub!"); + /* dump the bloody list */ + written = 0; + remaining = in->n * in->settings->stride; + do { + ret = write(in->fd, in->cache + written, remaining); + if (ret < 0) { + try(errno != EAGAIN, err, errno, "Writing to stream failed with %zi", ret); + } else { + written += ret; + remaining -= ret; + ret = 0; + } + } while (remaining); + +err: return ret; } |