summaryrefslogtreecommitdiff
path: root/src/libstddjb/siovec_gather.c
blob: b5fcbb78aa8e2e75dfab8dddc885b2b2c2653d4d (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_gather (struct iovec const *v, unsigned int n, char *s, size_t max)
{
  size_t w = 0 ;
  unsigned int i = 0 ;
  for (; i < n && w < max ; i++)
  {
    size_t len = v[i].iov_len ;
    if ((w + len) > max) len = max - w ;
    memmove(s + w, v[i].iov_base, len) ;
    w += len ;
  }
  return w ;
}