summaryrefslogtreecommitdiffstats
path: root/mandoc.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-10-28 19:21:59 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-10-28 19:21:59 +0000
commit96653104d83f28e58819b18170145bf8ebd3fcd2 (patch)
tree49cfe322a6a755ae95ecb75fb10617a6551853dd /mandoc.c
parent8ab24f2ea4960118f60f8c80f5ce3be7aab59fbb (diff)
downloadmandoc-96653104d83f28e58819b18170145bf8ebd3fcd2.tar.gz
Slow movement of internal allocations to fail completely.
Diffstat (limited to 'mandoc.c')
-rw-r--r--mandoc.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/mandoc.c b/mandoc.c
index 0ec1d573..086e7cd9 100644
--- a/mandoc.c
+++ b/mandoc.c
@@ -19,6 +19,8 @@
#include <assert.h>
#include <ctype.h>
#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
#include "libmandoc.h"
@@ -103,3 +105,74 @@ mandoc_special(const char *p)
return(*p == ']' ? c : 0);
}
+
+void *
+mandoc_calloc(size_t num, size_t size)
+{
+ void *ptr;
+
+ ptr = calloc(num, size);
+ if (NULL == ptr) {
+ fprintf(stderr, "memory exhausted\n");
+ exit(EXIT_FAILURE);
+ }
+
+ return(ptr);
+}
+
+
+void *
+mandoc_malloc(size_t size)
+{
+ void *ptr;
+
+ ptr = malloc(size);
+ if (NULL == ptr) {
+ fprintf(stderr, "memory exhausted\n");
+ exit(EXIT_FAILURE);
+ }
+
+ return(ptr);
+}
+
+
+void *
+mandoc_realloc(void *ptr, size_t size)
+{
+
+ ptr = realloc(ptr, size);
+ if (NULL == ptr) {
+ fprintf(stderr, "memory exhausted\n");
+ exit(EXIT_FAILURE);
+ }
+
+ return(ptr);
+}
+
+
+void *
+mandoc_reallocf(void *old_ptr, size_t size) /* FIXME: remove (not used) */
+{
+ void *ptr;
+
+ ptr = realloc(old_ptr, size);
+ if (NULL == ptr)
+ free(old_ptr);
+
+ return(ptr);
+}
+
+
+char *
+mandoc_strdup(const char *ptr)
+{
+ char *p;
+
+ p = strdup(ptr);
+ if (NULL == p) {
+ fprintf(stderr, "memory exhausted\n");
+ exit(EXIT_FAILURE);
+ }
+
+ return(p);
+}