summaryrefslogtreecommitdiff
path: root/src/libstddjb/siovec_deal.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2014-09-18 18:55:44 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2014-09-18 18:55:44 +0000
commit3534b428629be185e096be99e3bd5fdfe32d5544 (patch)
tree210ef3198ed66bc7f7b7bf6a85e4579f455e5a36 /src/libstddjb/siovec_deal.c
downloadskalibs-3534b428629be185e096be99e3bd5fdfe32d5544.tar.xz
initial commit with rc for skalibs-2.0.0.0
Diffstat (limited to 'src/libstddjb/siovec_deal.c')
-rw-r--r--src/libstddjb/siovec_deal.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/libstddjb/siovec_deal.c b/src/libstddjb/siovec_deal.c
new file mode 100644
index 0000000..fffea92
--- /dev/null
+++ b/src/libstddjb/siovec_deal.c
@@ -0,0 +1,24 @@
+/* ISC license. */
+
+#include <skalibs/bytestr.h>
+#include <skalibs/siovec.h>
+
+unsigned int siovec_deal (siovec_t const *vj, unsigned int nj, siovec_t const *vi, unsigned int ni)
+{
+ unsigned int w = 0 ;
+ unsigned int i = 0 ;
+ unsigned int j = 0 ;
+ unsigned int wi = 0 ;
+ unsigned int wj = 0 ;
+ while (i < ni && j < nj)
+ {
+ register unsigned int tor = vi[i].len - wi ;
+ register unsigned int tow = vj[j].len - wj ;
+ register unsigned int len = tor < tow ? tor : tow ;
+ byte_copy(vj[j].s + wj, len, vi[i].s + wi) ;
+ wi += len ; wj += len ; w += len ;
+ if (wi >= vi[i].len) { wi = 0 ; i++ ; }
+ if (wj >= vj[j].len) { wj = 0 ; j++ ; }
+ }
+ return w ;
+}