diff --git a/docs/c-api/mbuf.h/intro.md b/docs/c-api/mbuf.h/intro.md index 056369a2..5779ab9c 100644 --- a/docs/c-api/mbuf.h/intro.md +++ b/docs/c-api/mbuf.h/intro.md @@ -4,6 +4,7 @@ symbol_kind: "intro" decl_name: "mbuf.h" items: - { name: mbuf_append.md } + - { name: mbuf_clear.md } - { name: mbuf_free.md } - { name: mbuf_init.md } - { name: mbuf_insert.md } diff --git a/docs/c-api/mbuf.h/mbuf_clear.md b/docs/c-api/mbuf.h/mbuf_clear.md new file mode 100644 index 00000000..afefc21a --- /dev/null +++ b/docs/c-api/mbuf.h/mbuf_clear.md @@ -0,0 +1,10 @@ +--- +title: "mbuf_clear()" +decl_name: "mbuf_clear" +symbol_kind: "func" +signature: | + void mbuf_clear(struct mbuf *); +--- + +Removes all the data from mbuf (if any). + diff --git a/mongoose.c b/mongoose.c index 76f35fe3..d3cd2bd5 100644 --- a/mongoose.c +++ b/mongoose.c @@ -1620,6 +1620,11 @@ void mbuf_remove(struct mbuf *mb, size_t n) { } } +void mbuf_clear(struct mbuf *mb) WEAK; +void mbuf_clear(struct mbuf *mb) { + mb->len = 0; +} + #endif /* EXCLUDE_COMMON */ #ifdef MG_MODULE_LINES #line 1 "common/mg_str.c" diff --git a/mongoose.h b/mongoose.h index 4b5b0db6..07cf98a1 100644 --- a/mongoose.h +++ b/mongoose.h @@ -2388,6 +2388,9 @@ void mbuf_remove(struct mbuf *, size_t data_size); */ void mbuf_resize(struct mbuf *, size_t new_size); +/* Removes all the data from mbuf (if any). */ +void mbuf_clear(struct mbuf *); + /* Shrinks an Mbuf by resizing its `size` to `len`. */ void mbuf_trim(struct mbuf *);