xref: /dragonfly/usr.sbin/zic/ialloc.c (revision 479ab7f0)
1 /*
2 ** This file is in the public domain, so clarified as of
3 ** 2006-07-17 by Arthur David Olson.
4 */
5 
6 /*
7  * $FreeBSD: src/usr.sbin/zic/ialloc.c,v 1.5 1999/08/28 01:21:18 peter Exp $
8  */
9 /*LINTLIBRARY*/
10 
11 #include "private.h"
12 
13 char *
14 icatalloc(char *const old, const char * const new)
15 {
16 	char *result;
17 	int oldsize, newsize;
18 
19 	newsize = (new == NULL) ? 0 : strlen(new);
20 	if (old == NULL)
21 		oldsize = 0;
22 	else if (newsize == 0)
23 		return old;
24 	else	oldsize = strlen(old);
25 	if ((result = realloc(old, oldsize + newsize + 1)) != NULL)
26 		if (new != NULL)
27 			strcpy(result + oldsize, new);
28 	return result;
29 }
30 
31 char *
32 icpyalloc(const char * const string)
33 {
34 	return icatalloc(NULL, string);
35 }
36