]> git.saurik.com Git - apple/system_cmds.git/blame - zic.tproj/ialloc.c
system_cmds-279.tar.gz
[apple/system_cmds.git] / zic.tproj / ialloc.c
CommitLineData
1815bff5
A
1/*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
c3a08f59
A
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.
1815bff5
A
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,
c3a08f59
A
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.
1815bff5
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25#if defined(LIBC_SCCS) && !defined(lint)
26#if 0
27static char elsieid[] = "@(#)ialloc.c 8.28";
28#else
29static 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
39char * icalloc P((int nelem, int elsize));
40char * icatalloc P((char * old, const char * new));
41char * icpyalloc P((const char * string));
42char * imalloc P((int n));
43void * irealloc P((void * pointer, int size));
44void ifree P((char * pointer));
45
46char *
47imalloc(n)
48const int n;
49{
50 return malloc((size_t) nonzero(n));
51}
52
53char *
54icalloc(nelem, elsize)
55int nelem;
56int elsize;
57{
58 if (nelem == 0 || elsize == 0)
59 nelem = elsize = 1;
60 return calloc((size_t) nelem, (size_t) elsize);
61}
62
63void *
64irealloc(pointer, size)
65void * const pointer;
66const int size;
67{
68 if (pointer == NULL)
69 return imalloc(size);
70 return realloc((void *) pointer, (size_t) nonzero(size));
71}
72
73char *
74icatalloc(old, new)
75char * const old;
76const 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
93char *
94icpyalloc(string)
95const char * const string;
96{
97 return icatalloc((char *) NULL, string);
98}
99
100void
101ifree(p)
102char * const p;
103{
104 if (p != NULL)
105 (void) free(p);
106}
107
108void
109icfree(p)
110char * const p;
111{
112 if (p != NULL)
113 (void) free(p);
114}