diff --git a/core/tbuf.c b/core/tbuf.c index bb9fb1369641ce0a1c182e186f0cb07faf9ad600..4e8e803ddca6be02cbddc1bcfd64efc2306018a1 100644 --- a/core/tbuf.c +++ b/core/tbuf.c @@ -124,17 +124,16 @@ tbuf_peek(struct tbuf *b, size_t count) return NULL; } -void * +/** Remove first count bytes from the beginning. */ + +void tbuf_ltrim(struct tbuf *b, size_t count) { - void *p = NULL; - tbuf_assert(b); - if (count <= b->len) { - p = memmove(b->data, b->data + count, b->len - count); - b->len -= count; - } - return p; + assert(count <= b->len); + + memmove(b->data, b->data + count, b->len - count); + b->len -= count; } size_t diff --git a/include/tbuf.h b/include/tbuf.h index e45d44fc094c24c685825d5085f4015c80fdca94..a504111a0ff0195f7e41154e7f103dae8acf3db3 100644 --- a/include/tbuf.h +++ b/include/tbuf.h @@ -63,7 +63,16 @@ struct tbuf *tbuf_split(struct tbuf *e, size_t at); size_t tbuf_reserve(struct tbuf *b, size_t count); void tbuf_reset(struct tbuf *b); void *tbuf_peek(struct tbuf *b, size_t count); -void *tbuf_ltrim(struct tbuf *b, size_t count); + +/** + * Remove count bytes from the beginning, and adjust all sizes + * accordingly. + * + * @param count the number of bytes to forget about. + * + * @pre 0 <= count <= tbuf->len + */ +void tbuf_ltrim(struct tbuf *b, size_t count); void tbuf_append_field(struct tbuf *b, void *f); void tbuf_vprintf(struct tbuf *b, const char *format, va_list ap)