]>
git.cameronkatri.com Git - mandoc.git/blob - xstd.c
1 /* $Id: xstd.c,v 1.10 2009/03/16 22:19:19 kristaps Exp $ */
3 * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the
7 * above copyright notice and this permission notice appear in all
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
27 * Contains wrappers for common functions to simplify their general
28 * usage throughout this codebase.
32 xstrcmp(const char *p1
, const char *p2
)
35 return(0 == strcmp(p1
, p2
));
39 xstrlcat(char *dst
, const char *src
, size_t sz
)
42 return(strlcat(dst
, src
, sz
) < sz
);
46 xstrlcpy(char *dst
, const char *src
, size_t sz
)
49 return(strlcpy(dst
, src
, sz
) < sz
);
53 xrealloc(void *ptr
, size_t sz
)
57 if (NULL
== (p
= realloc(ptr
, sz
)))
58 err(EXIT_FAILURE
, "realloc");
63 xcalloc(size_t num
, size_t sz
)
67 if (NULL
== (p
= calloc(num
, sz
)))
68 err(EXIT_FAILURE
, "calloc");
73 xstrdup(const char *p
)
77 if (NULL
== (pp
= strdup(p
)))
78 err(EXIT_FAILURE
, "strdup");
83 xstrlcpys(char *buf
, const struct mdoc_node
*n
, size_t sz
)
91 for ( ; n
; n
= n
->next
) {
92 assert(MDOC_TEXT
== n
->type
);
94 if ( ! xstrlcat(buf
, p
, sz
))
96 if (n
->next
&& ! xstrlcat(buf
, " ", sz
))