add UNLEASHED_OBJ to unleashed.mk
[unleashed/tickless.git] / usr / src / cmd / backup / lib / memutils.c
blobe46c33430bce135ad8e39a13258a9c9c6174e1ff
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright (c) 1998 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <stdlib.h>
30 #include <errno.h>
31 #include <libintl.h>
32 #include <string.h>
33 #include "memutils.h"
35 extern void msg(const char *, ...);
36 extern void dumpabort(void);
38 void *
39 xmalloc(bytes)
40 size_t bytes;
42 void *cp;
44 cp = malloc(bytes);
45 if (cp == NULL) {
46 int saverr = errno;
47 msg(gettext("Cannot allocate memory: %s\n"), strerror(saverr));
48 dumpabort();
50 return (cp);
53 void *
54 xcalloc(nelem, size)
55 size_t nelem;
56 size_t size;
58 void *cp;
60 cp = calloc(nelem, size);
61 if (cp == NULL) {
62 int saverr = errno;
63 msg(gettext("Cannot allocate memory: %s\n"), strerror(saverr));
64 dumpabort();
66 return (cp);
69 void *
70 xrealloc(allocated, newsize)
71 void *allocated;
72 size_t newsize;
74 void *cp;
76 /* LINTED realloc knows what to do with a NULL pointer */
77 cp = realloc(allocated, newsize);
78 if (cp == NULL) {
79 int saverr = errno;
80 msg(gettext("Cannot allocate memory: %s\n"), strerror(saverr));
81 dumpabort();
83 return (cp);