2013-12-06 12:04:52 +01:00
|
|
|
/* $NetBSD: ialloc.c,v 1.9 2012/10/26 18:29:34 christos Exp $ */
|
2011-02-14 20:36:03 +01:00
|
|
|
/*
|
|
|
|
** This file is in the public domain, so clarified as of
|
|
|
|
** 2006-07-17 by Arthur David Olson.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if HAVE_NBTOOL_CONFIG_H
|
|
|
|
#include "nbtool_config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static char elsieid[] = "@(#)ialloc.c 8.30";
|
|
|
|
#else
|
2013-12-06 12:04:52 +01:00
|
|
|
__RCSID("$NetBSD: ialloc.c,v 1.9 2012/10/26 18:29:34 christos Exp $");
|
2011-02-14 20:36:03 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "private.h"
|
|
|
|
|
|
|
|
char *
|
2013-12-06 12:04:52 +01:00
|
|
|
icatalloc(char *const old, const char *const new)
|
2011-02-14 20:36:03 +01:00
|
|
|
{
|
2013-12-06 12:04:52 +01:00
|
|
|
char * result;
|
|
|
|
int oldsize, newsize;
|
2011-02-14 20:36:03 +01:00
|
|
|
|
|
|
|
newsize = (new == NULL) ? 0 : strlen(new);
|
|
|
|
if (old == NULL)
|
|
|
|
oldsize = 0;
|
|
|
|
else if (newsize == 0)
|
|
|
|
return old;
|
|
|
|
else
|
|
|
|
oldsize = strlen(old);
|
2013-12-06 12:04:52 +01:00
|
|
|
if ((result = realloc(old, oldsize + newsize + 1)) != NULL)
|
2011-02-14 20:36:03 +01:00
|
|
|
if (new != NULL)
|
|
|
|
(void) strcpy(result + oldsize, new); /* XXX strcpy is safe */
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2013-12-06 12:04:52 +01:00
|
|
|
icpyalloc(const char *const string)
|
2011-02-14 20:36:03 +01:00
|
|
|
{
|
2013-12-06 12:04:52 +01:00
|
|
|
return icatalloc(NULL, string);
|
2011-02-14 20:36:03 +01:00
|
|
|
}
|