skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

siovec_trunc.c (384B)


      1 /* ISC license. */
      2 
      3 #include <sys/uio.h>
      4 #include <skalibs/siovec.h>
      5 
      6 unsigned int siovec_trunc (struct iovec *v, unsigned int n, size_t len)
      7 {
      8   size_t w = siovec_len(v, n) ;
      9   if (w < len) return n ;
     10   len = w - len ;
     11   while (n && len)
     12   {
     13     w = len > v[n-1].iov_len ? v[n-1].iov_len : len ;
     14     v[n-1].iov_len -= w ; len -= w ;
     15     if (!v[n-1].iov_len) n-- ;
     16   }
     17   return n ;
     18 }