summaryrefslogtreecommitdiff
path: root/src/libstddjb/cbuffer_wpeek.c
blob: d02329440da820d6e117409ec62a6ffe59ddb8aa (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 <sys/uio.h>
#include <skalibs/cbuffer.h>

void cbuffer_wpeek (cbuffer_t const *b, struct iovec *v)
{
  size_t last = (b->a - 1 + b->p) % b->a ;
  v[0].iov_base = b->x + b->n ;
  if (last >= b->n)
  {
    v[0].iov_len = last - b->n ;
    v[1].iov_base = 0 ;
    v[1].iov_len = 0 ;
  }
  else
  {
    v[0].iov_len = b->a - b->n ;
    v[1].iov_base = b->x ;
    v[1].iov_len = last ;
  }
}