]>
git.saurik.com Git - apple/system_cmds.git/blob - zic.tproj/ialloc.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
25 #if defined(LIBC_SCCS) && !defined(lint)
27 static char elsieid
[] = "@(#)ialloc.c 8.28";
29 static char rcsid
[] = "$OpenBSD: ialloc.c,v 1.3 1997/01/14 03:16:45 millert Exp $";
31 #endif /* LIBC_SCCS and not lint */
37 #define nonzero(n) (((n) == 0) ? 1 : (n))
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
));
50 return malloc((size_t) nonzero(n
));
54 icalloc(nelem
, elsize
)
58 if (nelem
== 0 || elsize
== 0)
60 return calloc((size_t) nelem
, (size_t) elsize
);
64 irealloc(pointer
, size
)
70 return realloc((void *) pointer
, (size_t) nonzero(size
));
76 const char * const new;
78 register char * result
;
79 register int oldsize
, newsize
;
81 newsize
= (new == NULL
) ? 0 : strlen(new);
84 else if (newsize
== 0)
86 else oldsize
= strlen(old
);
87 if ((result
= irealloc(old
, oldsize
+ newsize
+ 1)) != NULL
)
89 (void) strcpy(result
+ oldsize
, new);
95 const char * const string
;
97 return icatalloc((char *) NULL
, string
);