summaryrefslogtreecommitdiff
path: root/src/libstddjb/siovec_seek.c
blob: 34a8918b4f8b96ed17d1bf9172c9e5dde14998c0 (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
/* ISC license. */

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

unsigned int siovec_seek (siovec_t *v, unsigned int n, unsigned int len)
{
  unsigned int w = 0 ;
  register unsigned int i = 0 ;
  for (; i < n ; i++)
  {
    if (len < v[i].len) break ;
    w += v[i].len ;
    len -= v[i].len ;
    v[i].s = 0 ;
    v[i].len = 0 ;
  }
  if (i < n)
  {
    v[i].s += len ;
    v[i].len -= len ;
    w += len ;
  }
  return w ;
}