1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

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:
Koen Zandberg 2018-08-31 10:35:02 +02:00
parent dc8c983d26
commit 8d9cb25ed7
No known key found for this signature in database
GPG Key ID: 0895A893E6D2985B
2 changed files with 18 additions and 0 deletions

View File

@ -127,6 +127,14 @@ int tsrb_get_one(tsrb_t *rb);
*/
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
* @param[in] rb Ringbuffer to operate on

View File

@ -49,6 +49,16 @@ int tsrb_get(tsrb_t *rb, char *dst, size_t n)
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)
{
if (!tsrb_full(rb)) {