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

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

void cbuffer_wpeek (cbuffer_t *b, siovec_t *v)
{
  unsigned int last = (b->a - 1 + b->p) % b->a ;
  v[0].s = b->x + b->n ;
  if (last >= b->n)
  {
    v[0].len = last - b->n ;
    v[1].s = 0 ;
    v[1].len = 0 ;
  }
  else
  {
    v[0].len = b->a - b->n ;
    v[1].s = b->x ;
    v[1].len = last ;
  }
}