2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 #include <mach/mach.h>
28 #include "stuff/allocate.h"
29 #include "stuff/errors.h"
31 * allocate() is just a wrapper around malloc that prints an error message and
32 * exits if the malloc fails.
43 if((p
= malloc(size
)) == NULL
)
44 system_fatal("virtual memory exhausted (malloc failed)");
49 * reallocate() is just a wrapper around realloc that prints and error message
50 * and exits if the realloc fails.
59 return(allocate(size
));
60 if((p
= realloc(p
, size
)) == NULL
)
61 system_fatal("virtual memory exhausted (realloc failed)");
66 * savestr() malloc's space for the string passed to it, copys the string into
67 * the space and returns a pointer to that space.
78 r
= (char *)allocate(len
);
84 * Makestr() creates a string that is the concatenation of a variable number of
85 * strings. It is pass a variable number of pointers to strings and the last
86 * pointer is NULL. It returns the pointer to the string it created. The
87 * storage for the string is malloc()'ed can be free()'ed when nolonger needed.
101 size
+= strlen(args
);
103 p
= (char *)va_arg(ap
, char *);
106 p
= (char *)va_arg(ap
, char *);
109 s
= allocate(size
+ 1);
113 (void)strcat(s
, args
);
115 p
= (char *)va_arg(ap
, char *);
118 p
= (char *)va_arg(ap
, char *);