]>
git.saurik.com Git - apple/system_cmds.git/blob - zic.tproj/ialloc.c
490d2faf522f736cf14fe50fbdbf56b1a3beab69
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
24 #if defined(LIBC_SCCS) && !defined(lint)
26 static char elsieid
[] = "@(#)ialloc.c 8.28";
28 static char rcsid
[] = "$OpenBSD: ialloc.c,v 1.3 1997/01/14 03:16:45 millert Exp $";
30 #endif /* LIBC_SCCS and not lint */
36 #define nonzero(n) (((n) == 0) ? 1 : (n))
38 char * icalloc
P((int nelem
, int elsize
));
39 char * icatalloc
P((char * old
, const char * new));
40 char * icpyalloc
P((const char * string
));
41 char * imalloc
P((int n
));
42 void * irealloc
P((void * pointer
, int size
));
43 void ifree
P((char * pointer
));
49 return malloc((size_t) nonzero(n
));
53 icalloc(nelem
, elsize
)
57 if (nelem
== 0 || elsize
== 0)
59 return calloc((size_t) nelem
, (size_t) elsize
);
63 irealloc(pointer
, size
)
69 return realloc((void *) pointer
, (size_t) nonzero(size
));
75 const char * const new;
77 register char * result
;
78 register int oldsize
, newsize
;
80 newsize
= (new == NULL
) ? 0 : strlen(new);
83 else if (newsize
== 0)
85 else oldsize
= strlen(old
);
86 if ((result
= irealloc(old
, oldsize
+ newsize
+ 1)) != NULL
)
88 (void) strcpy(result
+ oldsize
, new);
94 const char * const string
;
96 return icatalloc((char *) NULL
, string
);