summaryrefslogtreecommitdiff
path: root/src/cmark.c
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2016-06-06 11:45:47 +0200
committerJohn MacFarlane <jgm@berkeley.edu>2016-06-06 15:39:06 -0700
commitfc1299a51ede05b3a76ae2f5a3ce882741a43a8b (patch)
treed8c8de49a2cb7c3bab832556e25f2648a7c6e8d0 /src/cmark.c
parent27376c2150df53d23995c0360a30152f68af5e7c (diff)
mem: Add a `realloc` pointer to the memory handler
Diffstat (limited to 'src/cmark.c')
-rw-r--r--src/cmark.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/cmark.c b/src/cmark.c
index 3491199..d5fef63 100644
--- a/src/cmark.c
+++ b/src/cmark.c
@@ -10,6 +10,20 @@ int cmark_version() { return CMARK_VERSION; }
const char *cmark_version_string() { return CMARK_VERSION_STRING; }
+static void *xcalloc(size_t nmem, size_t size) {
+ void *ptr = calloc(nmem, size);
+ if (!ptr) abort();
+ return ptr;
+}
+
+static void *xrealloc(void *ptr, size_t size) {
+ void *new_ptr = realloc(ptr, size);
+ if (!new_ptr) abort();
+ return new_ptr;
+}
+
+cmark_mem DEFAULT_MEM_ALLOCATOR = { xcalloc, xrealloc, free };
+
char *cmark_markdown_to_html(const char *text, size_t len, int options) {
cmark_node *doc;
char *result;