summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-03-17 08:49:34 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-03-17 08:49:34 +0000
commitb115f948b8e55e6c3cef4bfa81f62c190af37a59 (patch)
tree36b8ace377de1911ede7b7fca7e4ce75035928c9
parent684938dc1d7c8591d0b63657a1d36b25b24eaea8 (diff)
downloadmandoc-b115f948b8e55e6c3cef4bfa81f62c190af37a59.tar.gz
Move mandoc_{realloc,malloc,calloc} out of libmandoc.h and into mandoc.h
so that everybody can use them. This follows the convention of libXXXX.h being internal to a library and XXXX.h being the external interface. Not only does this allow the removal of lots of redundant NULL-checking code, it also sets the tone for adding new mandoc-global routines.
-rw-r--r--chars.c13
-rw-r--r--html.c12
-rw-r--r--libmandoc.h3
-rw-r--r--main.c6
-rw-r--r--mandoc.h12
-rw-r--r--out.c2
-rw-r--r--term.c13
-rw-r--r--term_ps.c7
8 files changed, 15 insertions, 53 deletions
diff --git a/chars.c b/chars.c
index ae478800..270d4f50 100644
--- a/chars.c
+++ b/chars.c
@@ -92,17 +92,8 @@ chars_init(enum chars type)
* (they're in-line re-ordered during lookup).
*/
- tab = malloc(sizeof(struct ctab));
- if (NULL == tab) {
- perror(NULL);
- exit((int)MANDOCLEVEL_SYSERR);
- }
-
- htab = calloc(PRINT_HI - PRINT_LO + 1, sizeof(struct ln **));
- if (NULL == htab) {
- perror(NULL);
- exit((int)MANDOCLEVEL_SYSERR);
- }
+ tab = mandoc_malloc(sizeof(struct ctab));
+ htab = mandoc_calloc(PRINT_HI - PRINT_LO + 1, sizeof(struct ln **));
for (i = 0; i < LINES_MAX; i++) {
hash = (int)lines[i].code[0] - PRINT_LO;
diff --git a/html.c b/html.c
index ce801013..5c042581 100644
--- a/html.c
+++ b/html.c
@@ -120,11 +120,7 @@ ml_alloc(char *outopts, enum htmltype type)
toks[2] = "includes";
toks[3] = NULL;
- h = calloc(1, sizeof(struct html));
- if (NULL == h) {
- perror(NULL);
- exit((int)MANDOCLEVEL_SYSERR);
- }
+ h = mandoc_calloc(1, sizeof(struct html));
h->type = type;
h->tags.head = NULL;
@@ -400,11 +396,7 @@ print_otag(struct html *h, enum htmltag tag,
/* Push this tags onto the stack of open scopes. */
if ( ! (HTML_NOSTACK & htmltags[tag].flags)) {
- t = malloc(sizeof(struct tag));
- if (NULL == t) {
- perror(NULL);
- exit((int)MANDOCLEVEL_SYSERR);
- }
+ t = mandoc_malloc(sizeof(struct tag));
t->tag = tag;
t->next = h->tags.head;
h->tags.head = t;
diff --git a/libmandoc.h b/libmandoc.h
index 83409a82..f7a54f2b 100644
--- a/libmandoc.h
+++ b/libmandoc.h
@@ -20,10 +20,7 @@
__BEGIN_DECLS
int mandoc_special(char *);
-void *mandoc_calloc(size_t, size_t);
char *mandoc_strdup(const char *);
-void *mandoc_malloc(size_t);
-void *mandoc_realloc(void *, size_t);
char *mandoc_getarg(char **, mandocmsg, void *, int, int *);
char *mandoc_normdate(char *, mandocmsg, void *, int, int);
int mandoc_eos(const char *, size_t, int);
diff --git a/main.c b/main.c
index 31f53975..b06e9749 100644
--- a/main.c
+++ b/main.c
@@ -405,11 +405,7 @@ resize_buf(struct buf *buf, size_t initial)
{
buf->sz = buf->sz > initial/2 ? 2 * buf->sz : initial;
- buf->buf = realloc(buf->buf, buf->sz);
- if (NULL == buf->buf) {
- perror(NULL);
- exit((int)MANDOCLEVEL_SYSERR);
- }
+ buf->buf = mandoc_realloc(buf->buf, buf->sz);
}
diff --git a/mandoc.h b/mandoc.h
index 4aad6f3a..71cca22c 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -312,14 +312,14 @@ struct regset {
struct reg regs[REG__MAX];
};
+typedef int (*mandocmsg)(enum mandocerr, void *,
+ int, int, const char *);
+
__BEGIN_DECLS
-/*
- * Callback function for warnings, errors, and fatal errors as they
- * occur in the compilers libroff, libmdoc, and libman.
- */
-typedef int (*mandocmsg)(enum mandocerr, void *,
- int, int, const char *);
+void *mandoc_calloc(size_t, size_t);
+void *mandoc_malloc(size_t);
+void *mandoc_realloc(void *, size_t);
__END_DECLS
diff --git a/out.c b/out.c
index 44cc0eae..97da8498 100644
--- a/out.c
+++ b/out.c
@@ -431,7 +431,7 @@ tblcalc(struct rofftbl *tbl, const struct tbl_span *sp)
*/
assert(NULL == tbl->cols);
- tbl->cols = calloc
+ tbl->cols = mandoc_calloc
((size_t)sp->tbl->cols, sizeof(struct roffcol));
hp = sp->head;
diff --git a/term.c b/term.c
index 6b48196b..a106224b 100644
--- a/term.c
+++ b/term.c
@@ -80,12 +80,7 @@ term_alloc(enum termenc enc)
{
struct termp *p;
- p = calloc(1, sizeof(struct termp));
- if (NULL == p) {
- perror(NULL);
- exit((int)MANDOCLEVEL_SYSERR);
- }
-
+ p = mandoc_calloc(1, sizeof(struct termp));
p->enc = enc;
return(p);
}
@@ -579,11 +574,7 @@ adjbuf(struct termp *p, size_t sz)
while (sz >= p->maxcols)
p->maxcols <<= 2;
- p->buf = realloc(p->buf, p->maxcols);
- if (NULL == p->buf) {
- perror(NULL);
- exit((int)MANDOCLEVEL_SYSERR);
- }
+ p->buf = mandoc_realloc(p->buf, p->maxcols);
}
diff --git a/term_ps.c b/term_ps.c
index 78d4197b..f58db20f 100644
--- a/term_ps.c
+++ b/term_ps.c
@@ -366,14 +366,9 @@ ps_growbuf(struct termp *p, size_t sz)
p->engine.ps.psmargsz += sz;
- p->engine.ps.psmarg = realloc
+ p->engine.ps.psmarg = mandoc_realloc
(p->engine.ps.psmarg,
p->engine.ps.psmargsz);
-
- if (NULL == p->engine.ps.psmarg) {
- perror(NULL);
- exit((int)MANDOCLEVEL_SYSERR);
- }
}
static double ps_hspan(const struct termp *,