1192625Sedwin/* 2192625Sedwin** This file is in the public domain, so clarified as of 3192625Sedwin** 2006-07-17 by Arthur David Olson. 4192625Sedwin*/ 5192625Sedwin 62702Swollman#ifndef lint 72702Swollman#ifndef NOID 8192625Sedwinstatic const char elsieid[] = "@(#)ialloc.c 8.30"; 92702Swollman#endif /* !defined NOID */ 102702Swollman#endif /* !defined lint */ 112702Swollman 1230829Scharnier#ifndef lint 1330829Scharnierstatic const char rcsid[] = 1450479Speter "$FreeBSD$"; 1530829Scharnier#endif /* not lint */ 1630829Scharnier 172702Swollman/*LINTLIBRARY*/ 182702Swollman 192702Swollman#include "private.h" 202702Swollman 212702Swollman#define nonzero(n) (((n) == 0) ? 1 : (n)) 222702Swollman 232702Swollmanchar * 242702Swollmanimalloc(n) 252702Swollmanconst int n; 262702Swollman{ 279937Swollman return malloc((size_t) nonzero(n)); 282702Swollman} 292702Swollman 302702Swollmanchar * 312702Swollmanicalloc(nelem, elsize) 322702Swollmanint nelem; 332702Swollmanint elsize; 342702Swollman{ 352702Swollman if (nelem == 0 || elsize == 0) 362702Swollman nelem = elsize = 1; 379937Swollman return calloc((size_t) nelem, (size_t) elsize); 382702Swollman} 392702Swollman 409937Swollmanvoid * 412702Swollmanirealloc(pointer, size) 429937Swollmanvoid * const pointer; 432702Swollmanconst int size; 442702Swollman{ 459937Swollman if (pointer == NULL) 462702Swollman return imalloc(size); 479937Swollman return realloc((void *) pointer, (size_t) nonzero(size)); 482702Swollman} 492702Swollman 502702Swollmanchar * 512702Swollmanicatalloc(old, new) 522702Swollmanchar * const old; 532702Swollmanconst char * const new; 542702Swollman{ 552702Swollman register char * result; 562702Swollman register int oldsize, newsize; 572702Swollman 589937Swollman newsize = (new == NULL) ? 0 : strlen(new); 599937Swollman if (old == NULL) 602702Swollman oldsize = 0; 612702Swollman else if (newsize == 0) 622702Swollman return old; 632702Swollman else oldsize = strlen(old); 642702Swollman if ((result = irealloc(old, oldsize + newsize + 1)) != NULL) 659937Swollman if (new != NULL) 662702Swollman (void) strcpy(result + oldsize, new); 672702Swollman return result; 682702Swollman} 692702Swollman 702702Swollmanchar * 712702Swollmanicpyalloc(string) 722702Swollmanconst char * const string; 732702Swollman{ 742702Swollman return icatalloc((char *) NULL, string); 752702Swollman} 762702Swollman 772702Swollmanvoid 782702Swollmanifree(p) 792702Swollmanchar * const p; 802702Swollman{ 819937Swollman if (p != NULL) 822702Swollman (void) free(p); 832702Swollman} 842702Swollman 852702Swollmanvoid 862702Swollmanicfree(p) 872702Swollmanchar * const p; 882702Swollman{ 899937Swollman if (p != NULL) 902702Swollman (void) free(p); 912702Swollman} 92