summaryrefslogtreecommitdiff
path: root/src/libstddjb/cbuffer_wpeek.c
blob: cb3fc5e22bdce65d15411d3d614aebf0ae8c51fe (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 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 ;
  }
}