summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Wellnhofer <wellnhofer@aevum.de>2020-01-18 22:25:41 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2020-01-23 08:25:54 -0800
commitdf7ef9ed7b5f418897df557c9de88eaba2174703 (patch)
tree8443433cdf19b86199d02282beb57bb62e3a6d7b /src
parent4ac601f05db29b6135a784228098e004ca198499 (diff)
Helper function to set C strings in nodes
Diffstat (limited to 'src')
-rw-r--r--src/node.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/node.c b/src/node.c
index c6c2902..147debf 100644
--- a/src/node.c
+++ b/src/node.c
@@ -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;