Use GNU style like the rest of the file for my last commit.
[dragonfly/vkernel-mp.git] / usr.sbin / zic / ialloc.c
blobecc9c6943a89442c9398efb3a0b46d02d0fa00e7
1 #ifndef lint
2 #ifndef NOID
3 static char elsieid[] = "@(#)ialloc.c 8.29";
4 #endif /* !defined NOID */
5 #endif /* !defined lint */
7 /*
8 * @(#)ialloc.c 8.29
9 * $FreeBSD: src/usr.sbin/zic/ialloc.c,v 1.5 1999/08/28 01:21:18 peter Exp $
10 * $DragonFly: src/usr.sbin/zic/ialloc.c,v 1.4 2004/12/18 23:48:15 swildner Exp $
12 /*LINTLIBRARY*/
14 #include "private.h"
16 #define nonzero(n) (((n) == 0) ? 1 : (n))
18 char *
19 imalloc(const int n)
21 return malloc((size_t) nonzero(n));
24 char *
25 icalloc(int nelem, int elsize)
27 if (nelem == 0 || elsize == 0)
28 nelem = elsize = 1;
29 return calloc((size_t) nelem, (size_t) elsize);
32 void *
33 irealloc(void *const pointer, const int size)
35 if (pointer == NULL)
36 return imalloc(size);
37 return realloc((void *) pointer, (size_t) nonzero(size));
40 char *
41 icatalloc(char *const old, const char *new)
43 char *result;
44 int oldsize, newsize;
46 newsize = (new == NULL) ? 0 : strlen(new);
47 if (old == NULL)
48 oldsize = 0;
49 else if (newsize == 0)
50 return old;
51 else oldsize = strlen(old);
52 if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
53 if (new != NULL)
54 strcpy(result + oldsize, new);
55 return result;
58 char *
59 icpyalloc(const char *string)
61 return icatalloc((char *) NULL, string);
64 void
65 ifree(char * const p)
67 if (p != NULL)
68 free(p);
71 void
72 icfree(char * const p)
74 if (p != NULL)
75 free(p);