Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/talloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,28 @@ void *trealloc(void *usr, size_t size) {
return mem;
}

/**
* Duplicate string
*
* @param str string to be copied
* @param parent pointer to previously talloc'ed memory chunk from which this
* chunk depends, or NULL.
*
* @return pointer to the allocated memory chunk, or NULL if there was an error.
*/
char *tstrdup(const char *str, void *parent) {
size_t size;
char *copy;

size = strlen(str) + 1;
if ((copy = talloc(size, parent)) == NULL) {
return NULL;
}
memcpy(copy, str, size);

return copy;
}

/**
* Deallocate all the descendants of parent(mem) recursively.
*
Expand Down