]> git.saurik.com Git - apple/system_cmds.git/blob - zic.tproj/ialloc.c
system_cmds-230.7.tar.gz
[apple/system_cmds.git] / zic.tproj / ialloc.c
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 #if defined(LIBC_SCCS) && !defined(lint)
26 #if 0
27 static char elsieid[] = "@(#)ialloc.c 8.28";
28 #else
29 static char rcsid[] = "$OpenBSD: ialloc.c,v 1.3 1997/01/14 03:16:45 millert Exp $";
30 #endif
31 #endif /* LIBC_SCCS and not lint */
32
33 /*LINTLIBRARY*/
34
35 #include "private.h"
36
37 #define nonzero(n) (((n) == 0) ? 1 : (n))
38
39 char * icalloc P((int nelem, int elsize));
40 char * icatalloc P((char * old, const char * new));
41 char * icpyalloc P((const char * string));
42 char * imalloc P((int n));
43 void * irealloc P((void * pointer, int size));
44 void ifree P((char * pointer));
45
46 char *
47 imalloc(n)
48 const int n;
49 {
50 return malloc((size_t) nonzero(n));
51 }
52
53 char *
54 icalloc(nelem, elsize)
55 int nelem;
56 int elsize;
57 {
58 if (nelem == 0 || elsize == 0)
59 nelem = elsize = 1;
60 return calloc((size_t) nelem, (size_t) elsize);
61 }
62
63 void *
64 irealloc(pointer, size)
65 void * const pointer;
66 const int size;
67 {
68 if (pointer == NULL)
69 return imalloc(size);
70 return realloc((void *) pointer, (size_t) nonzero(size));
71 }
72
73 char *
74 icatalloc(old, new)
75 char * const old;
76 const char * const new;
77 {
78 register char * result;
79 register int oldsize, newsize;
80
81 newsize = (new == NULL) ? 0 : strlen(new);
82 if (old == NULL)
83 oldsize = 0;
84 else if (newsize == 0)
85 return old;
86 else oldsize = strlen(old);
87 if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
88 if (new != NULL)
89 (void) strcpy(result + oldsize, new);
90 return result;
91 }
92
93 char *
94 icpyalloc(string)
95 const char * const string;
96 {
97 return icatalloc((char *) NULL, string);
98 }
99
100 void
101 ifree(p)
102 char * const p;
103 {
104 if (p != NULL)
105 (void) free(p);
106 }
107
108 void
109 icfree(p)
110 char * const p;
111 {
112 if (p != NULL)
113 (void) free(p);
114 }