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

lwsac_use_zero

This commit is contained in:
Andy Green 2019-03-28 13:07:45 +08:00
parent 080a72669b
commit fd1f4e4de7
2 changed files with 32 additions and 0 deletions

View file

@ -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
*

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_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)
{