summaryrefslogtreecommitdiff
path: root/src/ro_buffer.cc
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2021-11-17 22:34:57 +0100
committerJoel Klinghed <the_jk@spawned.biz>2021-11-17 22:34:57 +0100
commit6232d13f5321b87ddf12a1aa36b4545da45f173d (patch)
tree23f3316470a14136debd9d02f9e920ca2b06f4cc /src/ro_buffer.cc
Travel3: Simple image and video display site
Reads the images and videos from filesystem and builds a site in memroy.
Diffstat (limited to 'src/ro_buffer.cc')
-rw-r--r--src/ro_buffer.cc29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/ro_buffer.cc b/src/ro_buffer.cc
new file mode 100644
index 0000000..ee6208e
--- /dev/null
+++ b/src/ro_buffer.cc
@@ -0,0 +1,29 @@
+#include "common.hh"
+
+#include "ro_buffer.hh"
+
+#include <algorithm>
+
+size_t RoBuffer::read(RoBuffer* buf, void* data, size_t len) {
+ assert(buf);
+ assert(data);
+ if (len == 0)
+ return 0;
+ auto* d = reinterpret_cast<char*>(data);
+ size_t got = 0;
+ while (true) {
+ size_t avail;
+ auto want = len - got;
+ auto* ptr = buf->rbuf(want, avail);
+ if (avail == 0)
+ return got;
+ if (avail >= want) {
+ std::copy_n(ptr, want, d + got);
+ buf->rcommit(want);
+ return len;
+ }
+ std::copy_n(ptr, avail, d + got);
+ buf->rcommit(avail);
+ got += avail;
+ }
+}