1*4318c66eSSascha Wildner /* $NetBSD: alloc.c,v 1.9 2011/08/06 20:18:26 dholland Exp $ */
2984263bcSMatthew Dillon
3984263bcSMatthew Dillon /*
4*4318c66eSSascha Wildner * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
5*4318c66eSSascha Wildner * Amsterdam
6*4318c66eSSascha Wildner * All rights reserved.
7*4318c66eSSascha Wildner *
8*4318c66eSSascha Wildner * Redistribution and use in source and binary forms, with or without
9*4318c66eSSascha Wildner * modification, are permitted provided that the following conditions are
10*4318c66eSSascha Wildner * met:
11*4318c66eSSascha Wildner *
12*4318c66eSSascha Wildner * - Redistributions of source code must retain the above copyright notice,
13*4318c66eSSascha Wildner * this list of conditions and the following disclaimer.
14*4318c66eSSascha Wildner *
15*4318c66eSSascha Wildner * - Redistributions in binary form must reproduce the above copyright
16*4318c66eSSascha Wildner * notice, this list of conditions and the following disclaimer in the
17*4318c66eSSascha Wildner * documentation and/or other materials provided with the distribution.
18*4318c66eSSascha Wildner *
19*4318c66eSSascha Wildner * - Neither the name of the Stichting Centrum voor Wiskunde en
20*4318c66eSSascha Wildner * Informatica, nor the names of its contributors may be used to endorse or
21*4318c66eSSascha Wildner * promote products derived from this software without specific prior
22*4318c66eSSascha Wildner * written permission.
23*4318c66eSSascha Wildner *
24*4318c66eSSascha Wildner * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25*4318c66eSSascha Wildner * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26*4318c66eSSascha Wildner * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27*4318c66eSSascha Wildner * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
28*4318c66eSSascha Wildner * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29*4318c66eSSascha Wildner * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30*4318c66eSSascha Wildner * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31*4318c66eSSascha Wildner * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32*4318c66eSSascha Wildner * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33*4318c66eSSascha Wildner * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34*4318c66eSSascha Wildner * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35984263bcSMatthew Dillon */
366693db17SSascha Wildner
37*4318c66eSSascha Wildner /*
38*4318c66eSSascha Wildner * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
39*4318c66eSSascha Wildner * All rights reserved.
40*4318c66eSSascha Wildner *
41*4318c66eSSascha Wildner * Redistribution and use in source and binary forms, with or without
42*4318c66eSSascha Wildner * modification, are permitted provided that the following conditions
43*4318c66eSSascha Wildner * are met:
44*4318c66eSSascha Wildner * 1. Redistributions of source code must retain the above copyright
45*4318c66eSSascha Wildner * notice, this list of conditions and the following disclaimer.
46*4318c66eSSascha Wildner * 2. Redistributions in binary form must reproduce the above copyright
47*4318c66eSSascha Wildner * notice, this list of conditions and the following disclaimer in the
48*4318c66eSSascha Wildner * documentation and/or other materials provided with the distribution.
49*4318c66eSSascha Wildner * 3. The name of the author may not be used to endorse or promote products
50*4318c66eSSascha Wildner * derived from this software without specific prior written permission.
51*4318c66eSSascha Wildner *
52*4318c66eSSascha Wildner * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
53*4318c66eSSascha Wildner * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
54*4318c66eSSascha Wildner * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
55*4318c66eSSascha Wildner * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
56*4318c66eSSascha Wildner * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
57*4318c66eSSascha Wildner * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
58*4318c66eSSascha Wildner * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
59*4318c66eSSascha Wildner * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
60*4318c66eSSascha Wildner * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
61*4318c66eSSascha Wildner * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62*4318c66eSSascha Wildner */
63984263bcSMatthew Dillon
64*4318c66eSSascha Wildner #include <stdlib.h>
65*4318c66eSSascha Wildner #include "hack.h"
66*4318c66eSSascha Wildner #include "extern.h"
67984263bcSMatthew Dillon
68c7106d58SPeter Avalos void *
alloc(size_t len)69*4318c66eSSascha Wildner alloc(size_t len)
70984263bcSMatthew Dillon {
71c7106d58SPeter Avalos void *ptr;
72984263bcSMatthew Dillon
73*4318c66eSSascha Wildner ptr = malloc(len);
74*4318c66eSSascha Wildner if (ptr == NULL)
75*4318c66eSSascha Wildner panic("Cannot get %zu bytes", len);
76*4318c66eSSascha Wildner return ptr;
77984263bcSMatthew Dillon }
78984263bcSMatthew Dillon
79*4318c66eSSascha Wildner #if 0 /* unused */
80*4318c66eSSascha Wildner static long *
81*4318c66eSSascha Wildner enlarge(char *ptr, unsigned lth)
82*4318c66eSSascha Wildner {
83*4318c66eSSascha Wildner char *nptr;
84*4318c66eSSascha Wildner
85*4318c66eSSascha Wildner if (!(nptr = realloc(ptr, lth)))
86*4318c66eSSascha Wildner panic("Cannot reallocate %d bytes", lth);
87*4318c66eSSascha Wildner return ((long *) nptr);
88*4318c66eSSascha Wildner }
89*4318c66eSSascha Wildner #endif
90