diff options
Diffstat (limited to 'src/libstddjb/siovec_deal.c')
-rw-r--r-- | src/libstddjb/siovec_deal.c | 24 |
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 ; +} |