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

#include <skalibs/bytestr.h>
#include <skalibs/siovec.h>

unsigned int siovec_trunc (siovec_t *v, unsigned int n, unsigned int len)
{
  register unsigned int i = siovec_len(v, n) ;
  if (i < len) return n ;
  len = i - len ;
  i = n ;
  while (len && i--)
  {
    register unsigned int w = len > v[i].len ? v[i].len : len ;
    v[i].len -= w ; len -= w ;
  }
  return i ;
}