Sync usage with man page.
[netbsd-mini2440.git] / lib / libc / time / ialloc.c
blobae96543c3415871aa4f89c434ad93f9ca10c9267
1 /* $NetBSD: ialloc.c,v 1.6 2009/12/31 22:49:16 mlelstv Exp $ */
2 /*
3 ** This file is in the public domain, so clarified as of
4 ** 2006-07-17 by Arthur David Olson.
5 */
7 #if HAVE_NBTOOL_CONFIG_H
8 #include "nbtool_config.h"
9 #endif
11 #include <sys/cdefs.h>
13 #if 0
14 static char elsieid[] = "@(#)ialloc.c 8.30";
15 #else
16 __RCSID("$NetBSD: ialloc.c,v 1.6 2009/12/31 22:49:16 mlelstv Exp $");
17 #endif
19 #include "private.h"
21 #define nonzero(n) (((n) == 0) ? 1 : (n))
23 char *
24 imalloc(n)
25 const int n;
27 return malloc((size_t) nonzero(n));
30 char *
31 icalloc(nelem, elsize)
32 int nelem;
33 int elsize;
35 if (nelem == 0 || elsize == 0)
36 nelem = elsize = 1;
37 return calloc((size_t) nelem, (size_t) elsize);
40 void *
41 irealloc(pointer, size)
42 void * const pointer;
43 const int size;
45 if (pointer == NULL)
46 return imalloc(size);
47 return realloc((void *) pointer, (size_t) nonzero(size));
50 char *
51 icatalloc(old, new)
52 char * const old;
53 const char * const new;
55 register char * result;
56 register int oldsize, newsize;
58 newsize = (new == NULL) ? 0 : strlen(new);
59 if (old == NULL)
60 oldsize = 0;
61 else if (newsize == 0)
62 return old;
63 else
64 oldsize = strlen(old);
65 if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
66 if (new != NULL)
67 (void) strcpy(result + oldsize, new); /* XXX strcpy is safe */
68 return result;
71 char *
72 icpyalloc(string)
73 const char * const string;
75 return icatalloc((char *) NULL, string);
78 void
79 ifree(p)
80 char * const p;
82 if (p != NULL)
83 (void) free(p);
86 void
87 icfree(p)
88 char * const p;
90 if (p != NULL)
91 (void) free(p);