tsrb: add drop function
The get function does not support passing NULL as an input buffer. to be able to drop bytes from the buffer, a dedicated drop function is required
This commit is contained in:
parent
dc8c983d26
commit
8d9cb25ed7
@ -127,6 +127,14 @@ int tsrb_get_one(tsrb_t *rb);
|
|||||||
*/
|
*/
|
||||||
int tsrb_get(tsrb_t *rb, char *dst, size_t n);
|
int tsrb_get(tsrb_t *rb, char *dst, size_t n);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Drop bytes from ringbuffer
|
||||||
|
* @param[in] rb Ringbuffer to operate on
|
||||||
|
* @param[in] n max number of bytes to drop
|
||||||
|
* @return nr of bytes dropped
|
||||||
|
*/
|
||||||
|
int tsrb_drop(tsrb_t *rb, size_t n);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Add a byte to ringbuffer
|
* @brief Add a byte to ringbuffer
|
||||||
* @param[in] rb Ringbuffer to operate on
|
* @param[in] rb Ringbuffer to operate on
|
||||||
|
|||||||
@ -49,6 +49,16 @@ int tsrb_get(tsrb_t *rb, char *dst, size_t n)
|
|||||||
return (n - tmp);
|
return (n - tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int tsrb_drop(tsrb_t *rb, size_t n)
|
||||||
|
{
|
||||||
|
size_t tmp = n;
|
||||||
|
while (tmp && !tsrb_empty(rb)) {
|
||||||
|
_pop(rb);
|
||||||
|
tmp--;
|
||||||
|
}
|
||||||
|
return (n - tmp);
|
||||||
|
}
|
||||||
|
|
||||||
int tsrb_add_one(tsrb_t *rb, char c)
|
int tsrb_add_one(tsrb_t *rb, char c)
|
||||||
{
|
{
|
||||||
if (!tsrb_full(rb)) {
|
if (!tsrb_full(rb)) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user