1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 05:32:45 +01:00

Merge pull request #9869 from bergzand/pr/tsrb/drop

tsrb: add drop function
This commit is contained in:
Kaspar Schleiser 2018-09-18 10:57:55 +02:00 committed by GitHub
commit b518f3c73e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)) {