diff options
author | Nick Wellnhofer <wellnhofer@aevum.de> | 2020-01-18 22:25:41 +0100 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2020-01-23 08:25:54 -0800 |
commit | df7ef9ed7b5f418897df557c9de88eaba2174703 (patch) | |
tree | 8443433cdf19b86199d02282beb57bb62e3a6d7b /src | |
parent | 4ac601f05db29b6135a784228098e004ca198499 (diff) |
Helper function to set C strings in nodes
Diffstat (limited to 'src')
-rw-r--r-- | src/node.c | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -249,6 +249,26 @@ cmark_node *cmark_node_last_child(cmark_node *node) { } } +static bufsize_t cmark_set_cstr(cmark_mem *mem, unsigned char **dst, + const char *src) { + unsigned char *old = *dst; + bufsize_t len; + + if (src && src[0]) { + len = (bufsize_t)strlen(src); + *dst = (unsigned char *)mem->realloc(NULL, len + 1); + memcpy(*dst, src, len + 1); + } else { + len = 0; + *dst = NULL; + } + if (old) { + mem->free(old); + } + + return len; +} + void *cmark_node_get_user_data(cmark_node *node) { if (node == NULL) { return NULL; |