diff --git a/include/libwebsockets/lws-lwsac.h b/include/libwebsockets/lws-lwsac.h index ea5453cc8..a45f4204b 100644 --- a/include/libwebsockets/lws-lwsac.h +++ b/include/libwebsockets/lws-lwsac.h @@ -99,6 +99,27 @@ lws_list_ptr_insert(lws_list_ptr *phead, lws_list_ptr *add, LWS_VISIBLE LWS_EXTERN void * lwsac_use(struct lwsac **head, size_t ensure, size_t chunk_size); +/** + * lwsac_use_zero - allocate / use some memory from a lwsac and zero it + * + * \param head: pointer to the lwsac list object + * \param ensure: the number of bytes we want to use + * \param chunk_size: 0, or the size of the chunk to (over)allocate if + * what we want won't fit in the current tail chunk. If + * 0, the default value of 4000 is used. If ensure is + * larger, it is used instead. + * + * This also serves to init the lwsac if *head is NULL. Basically it does + * whatever is necessary to return you a pointer to ensure bytes of memory + * reserved for the caller. + * + * \p ensure bytes at the return address are zeroed if the allocation succeeded. + * + * Returns NULL if OOM. + */ +LWS_VISIBLE LWS_EXTERN void * +lwsac_use_zero(struct lwsac **head, size_t ensure, size_t chunk_size); + /** * lwsac_use - allocate / use some memory from a lwsac * diff --git a/lib/misc/lwsac/lwsac.c b/lib/misc/lwsac/lwsac.c index d37f7ea1c..a401bbc7f 100644 --- a/lib/misc/lwsac/lwsac.c +++ b/lib/misc/lwsac/lwsac.c @@ -131,6 +131,17 @@ lwsac_use(struct lwsac **head, size_t ensure, size_t chunk_size) return (char *)(*head)->curr + ofs; } +void * +lwsac_use_zero(struct lwsac **head, size_t ensure, size_t chunk_size) +{ + void *p = lwsac_use(head, ensure, chunk_size); + + if (p) + memset(p, 0, ensure); + + return p; +} + void * lwsac_use_zeroed(struct lwsac **head, size_t ensure, size_t chunk_size) {