summaryrefslogtreecommitdiff
path: root/src/libstddjb/siovec_seek.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstddjb/siovec_seek.c')
-rw-r--r--src/libstddjb/siovec_seek.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/libstddjb/siovec_seek.c b/src/libstddjb/siovec_seek.c
new file mode 100644
index 0000000..34a8918
--- /dev/null
+++ b/src/libstddjb/siovec_seek.c
@@ -0,0 +1,25 @@
+/* ISC license. */
+
+#include <skalibs/bytestr.h>
+#include <skalibs/siovec.h>
+
+unsigned int siovec_seek (siovec_t *v, unsigned int n, unsigned int len)
+{
+ unsigned int w = 0 ;
+ register unsigned int i = 0 ;
+ for (; i < n ; i++)
+ {
+ if (len < v[i].len) break ;
+ w += v[i].len ;
+ len -= v[i].len ;
+ v[i].s = 0 ;
+ v[i].len = 0 ;
+ }
+ if (i < n)
+ {
+ v[i].s += len ;
+ v[i].len -= len ;
+ w += len ;
+ }
+ return w ;
+}