1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

lwsac_use_zeroed: lwsac helper equivalent to zalloc

This commit is contained in:
Andy Green 2019-03-12 08:05:09 +08:00
parent 6a88483f02
commit 80ff6ed0df
2 changed files with 29 additions and 0 deletions

View file

@ -99,6 +99,24 @@ 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 - allocate / use some memory from a lwsac
*
* \param head: pointer to the lwsac list object
* \param ensure: the number of bytes we want to use, which must be zeroed
* \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.
*
* Same as lwsac_use(), but \p ensure bytes of memory at the return address
* are zero'd before returning.
*
* Returns NULL if OOM.
*/
void *
lwsac_use_zeroed(struct lwsac **head, size_t ensure, size_t chunk_size);
/**
* lwsac_free - deallocate all chunks in the lwsac and set head NULL
*

View file

@ -131,6 +131,17 @@ lwsac_use(struct lwsac **head, size_t ensure, size_t chunk_size)
return (char *)(*head)->curr + ofs;
}
void *
lwsac_use_zeroed(struct lwsac **head, size_t ensure, size_t chunk_size)
{
void *r = lwsac_use(head, ensure, chunk_size);
if (r)
memset(r, 0, ensure);
return r;
}
void
lwsac_free(struct lwsac **head)
{