1 /* $NetBSD: ialloc.c,v 1.6 2009/12/31 22:49:16 mlelstv Exp $ */
3 ** This file is in the public domain, so clarified as of
4 ** 2006-07-17 by Arthur David Olson.
7 #if HAVE_NBTOOL_CONFIG_H
8 #include "nbtool_config.h"
11 #include <sys/cdefs.h>
14 static char elsieid
[] = "@(#)ialloc.c 8.30";
16 __RCSID("$NetBSD: ialloc.c,v 1.6 2009/12/31 22:49:16 mlelstv Exp $");
21 #define nonzero(n) (((n) == 0) ? 1 : (n))
27 return malloc((size_t) nonzero(n
));
31 icalloc(nelem
, elsize
)
35 if (nelem
== 0 || elsize
== 0)
37 return calloc((size_t) nelem
, (size_t) elsize
);
41 irealloc(pointer
, size
)
47 return realloc((void *) pointer
, (size_t) nonzero(size
));
53 const char * const new;
55 register char * result
;
56 register int oldsize
, newsize
;
58 newsize
= (new == NULL
) ? 0 : strlen(new);
61 else if (newsize
== 0)
64 oldsize
= strlen(old
);
65 if ((result
= irealloc(old
, oldsize
+ newsize
+ 1)) != NULL
)
67 (void) strcpy(result
+ oldsize
, new); /* XXX strcpy is safe */
73 const char * const string
;
75 return icatalloc((char *) NULL
, string
);