kernel - TMPFS - Bug fixing pass
[dragonfly.git] / usr.sbin / zic / ialloc.c
blob3c69147239c425accb66415a2c363e45799f3d15
1 /*
2 ** This file is in the public domain, so clarified as of
3 ** 2006-07-17 by Arthur David Olson.
4 */
6 /*
7 * @(#)ialloc.c 8.30
8 * $FreeBSD: src/usr.sbin/zic/ialloc.c,v 1.5 1999/08/28 01:21:18 peter Exp $
9 * $DragonFly: src/usr.sbin/zic/ialloc.c,v 1.5 2008/10/19 20:15:58 swildner Exp $
11 /*LINTLIBRARY*/
13 #include "private.h"
15 #define nonzero(n) (((n) == 0) ? 1 : (n))
17 char *
18 imalloc(const int n)
20 return malloc((size_t) nonzero(n));
23 char *
24 icalloc(int nelem, int elsize)
26 if (nelem == 0 || elsize == 0)
27 nelem = elsize = 1;
28 return calloc((size_t) nelem, (size_t) elsize);
31 void *
32 irealloc(void *const pointer, const int size)
34 if (pointer == NULL)
35 return imalloc(size);
36 return realloc((void *) pointer, (size_t) nonzero(size));
39 char *
40 icatalloc(char *const old, const char *new)
42 char *result;
43 int oldsize, newsize;
45 newsize = (new == NULL) ? 0 : strlen(new);
46 if (old == NULL)
47 oldsize = 0;
48 else if (newsize == 0)
49 return old;
50 else oldsize = strlen(old);
51 if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
52 if (new != NULL)
53 strcpy(result + oldsize, new);
54 return result;
57 char *
58 icpyalloc(const char *string)
60 return icatalloc(NULL, string);
63 void
64 ifree(char * const p)
66 if (p != NULL)
67 free(p);
70 void
71 icfree(char * const p)
73 if (p != NULL)
74 free(p);