summaryrefslogtreecommitdiff
path: root/src/libstddjb/siovec_seek.c
blob: f03b20a0442913a4b6057abe45b243527ee52d84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* ISC license. */

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

size_t siovec_seek (struct iovec *v, unsigned int n, size_t len)
{
  size_t w = 0 ;
  register unsigned int i = 0 ;
  for (; i < n ; i++)
  {
    if (len < v[i].iov_len) break ;
    w += v[i].iov_len ;
    len -= v[i].iov_len ;
    v[i].iov_base = 0 ;
    v[i].iov_len = 0 ;
  }
  if (i < n)
  {
    v[i].iov_base = (char *)v[i].iov_base + len ;
    v[i].iov_len -= len ;
    w += len ;
  }
  return w ;
}