cmark

My personal build of CMark ✏️

Commit
df7ef9ed7b5f418897df557c9de88eaba2174703
Parent
4ac601f05db29b6135a784228098e004ca198499
Author
Nick Wellnhofer <wellnhofer@aevum.de>
Date

Helper function to set C strings in nodes

Diffstat

1 file changed, 20 insertions, 0 deletions

Status File Name N° Changes Insertions Deletions
Modified src/node.c 20 20 0
diff --git 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;