Welcome to little lamb

Code » limb » release » tree

[release] / src / doc / buffer.h / buffer_rpeek.3.md

% limb manual
% buffer_rpeek(3)
% limb 0.1.0
% 2023-07-24

# NAME

buffer_rpeek, buffer_rseek - peek/seek into a reading I/O buffer

# SYNOPSIS

    #include <limb/buffer.h>

```pre hl
void buffer_rpeek(buffer *<em>buf</em>, struct iovec <em>v</em>[2])
size_t buffer_rseek(buffer *<em>buf</em>, size_t <em>len</em>)
```

# DESCRIPTION

The `buffer_rpeek`() macro allows to peek into a reading buffer's used space.
The array of vectors pointed by `v` will be set to the in-use space inside
the memory of the buffer pointed by `buf`, i.e. the data to be copied next
by a call to [buffer_get](3) or similar.

The `buffer_rseek`() macro will update the internals of the buffer pointed by
`buf` to move past the next `len` bytes of data from its internal memory space,
as if they had been read/consumed.

! NOTE:
! Because a buffer's internal memory is kept as a circular buffer (see
! [cbuffer.h](0) for more), the data might not be stored as a continuous block
! and requires a couple of vectors to possibly get the full space. Note than it
! is possible the second vector will be set to zero if not needed, however `v`
! should always point to an array of 2 elements.

Typically, one would use `buffer_rpeek`() to get the locations where to read
from the buffer, and  after all went well use `buffer_rseek`() to have said data
"removed" from the buffer.

# RETURN VALUE

The `buffer_rseek`() function returns the amount of bytes in use by which its
internal buffer shrunk, which may be less than `len` (even 0 if the buffer was
empty).

# SEE ALSO

[buffer_unget](3)