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

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

unsigned int siovec_trunc (struct iovec *v, unsigned int n, size_t len)
{
  size_t w = siovec_len(v, n) ;
  if (w < len) return n ;
  len = w - len ;
  while (n && len)
  {
    w = len > v[n-1].iov_len ? v[n-1].iov_len : len ;
    v[n-1].iov_len -= w ; len -= w ;
    if (!v[n-1].iov_len) n-- ;
  }
  return n ;
}