summaryrefslogtreecommitdiff
path: root/src/libstddjb/siovec_trunc.c
blob: d71f9d9b56f1d9cbffd1536e4820e7814494e024 (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) ;
  unsigned int i = n ;
  if (w < len) return n ;
  len = w - len ;
  while (len && i--)
  {
    w = len > v[i].iov_len ? v[i].iov_len : len ;
    v[i].iov_len -= w ; len -= w ;
  }
  return i ;
}