summaryrefslogtreecommitdiff
path: root/src/libstddjb/siovec_scatter.c
blob: 3a583f30128878906f6a543cd9e6b2eaa28898d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* ISC license. */

#include <sys/types.h>
#include <sys/uio.h>
#include <string.h>
#include <skalibs/siovec.h>

size_t siovec_scatter (struct iovec const *v, unsigned int n, char const *s, size_t len)
{
  size_t w = 0 ;
  unsigned int i = 0 ;
  for (; i < n && w < len ; i++)
  {
    size_t chunklen = v[i].iov_len ;
    if (w + chunklen > len) chunklen = len - w ;
    memmove(v[i].iov_base, s + w, chunklen) ;
    w += chunklen ;
  }
  return w ;
}