core: ptrbox: Add ptrbox_malloc() function
Signed-off-by: Ian Moffett <ian@mirocom.org>
This commit is contained in:
@@ -83,6 +83,28 @@ ptrbox_strdup(struct ptrbox *ptrbox, const char *s)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
ptrbox_malloc(struct ptrbox *ptrbox, size_t length)
|
||||||
|
{
|
||||||
|
struct ptrbox_entry *entry;
|
||||||
|
void *mem;
|
||||||
|
|
||||||
|
if (ptrbox == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((mem = malloc(length)) == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((entry = entry_from_data(mem)) == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ptrbox_add_entry(ptrbox, entry);
|
||||||
|
return mem;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ptrbox_init(struct ptrbox *ptrbox)
|
ptrbox_init(struct ptrbox *ptrbox)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -60,6 +60,17 @@ int ptrbox_init(struct ptrbox *ptrbox);
|
|||||||
*/
|
*/
|
||||||
char *ptrbox_strdup(struct ptrbox *ptrbox, const char *s);
|
char *ptrbox_strdup(struct ptrbox *ptrbox, const char *s);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Allocate a number of bytes on the heap and store the reference
|
||||||
|
*
|
||||||
|
* @ptrbox: Pointer box
|
||||||
|
* @length: Number of bytes to allocate
|
||||||
|
*
|
||||||
|
* Returns the base of the allocated memory on success, otherwise
|
||||||
|
* NULL on failure.
|
||||||
|
*/
|
||||||
|
void *ptrbox_malloc(struct ptrbox *ptrbox, size_t length);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Destroy all elements within a pointer box
|
* Destroy all elements within a pointer box
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user