alloc.c revision 1.5
11.5Sjsm/* $NetBSD: alloc.c,v 1.5 2003/04/02 18:36:33 jsm Exp $ */ 21.5Sjsm 31.5Sjsm/* 41.5Sjsm * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, 51.5Sjsm * Amsterdam 61.5Sjsm * All rights reserved. 71.5Sjsm * 81.5Sjsm * Redistribution and use in source and binary forms, with or without 91.5Sjsm * modification, are permitted provided that the following conditions are 101.5Sjsm * met: 111.5Sjsm * 121.5Sjsm * - Redistributions of source code must retain the above copyright notice, 131.5Sjsm * this list of conditions and the following disclaimer. 141.5Sjsm * 151.5Sjsm * - Redistributions in binary form must reproduce the above copyright 161.5Sjsm * notice, this list of conditions and the following disclaimer in the 171.5Sjsm * documentation and/or other materials provided with the distribution. 181.5Sjsm * 191.5Sjsm * - Neither the name of the Stichting Centrum voor Wiskunde en 201.5Sjsm * Informatica, nor the names of its contributors may be used to endorse or 211.5Sjsm * promote products derived from this software without specific prior 221.5Sjsm * written permission. 231.5Sjsm * 241.5Sjsm * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 251.5Sjsm * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 261.5Sjsm * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 271.5Sjsm * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 281.5Sjsm * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 291.5Sjsm * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 301.5Sjsm * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 311.5Sjsm * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 321.5Sjsm * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 331.5Sjsm * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 341.5Sjsm * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 351.5Sjsm */ 361.5Sjsm 371.5Sjsm/* 381.5Sjsm * Copyright (c) 1982 Jay Fenlason <hack@gnu.org> 391.5Sjsm * All rights reserved. 401.5Sjsm * 411.5Sjsm * Redistribution and use in source and binary forms, with or without 421.5Sjsm * modification, are permitted provided that the following conditions 431.5Sjsm * are met: 441.5Sjsm * 1. Redistributions of source code must retain the above copyright 451.5Sjsm * notice, this list of conditions and the following disclaimer. 461.5Sjsm * 2. Redistributions in binary form must reproduce the above copyright 471.5Sjsm * notice, this list of conditions and the following disclaimer in the 481.5Sjsm * documentation and/or other materials provided with the distribution. 491.5Sjsm * 3. The name of the author may not be used to endorse or promote products 501.5Sjsm * derived from this software without specific prior written permission. 511.5Sjsm * 521.5Sjsm * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 531.5Sjsm * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 541.5Sjsm * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 551.5Sjsm * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 561.5Sjsm * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 571.5Sjsm * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 581.5Sjsm * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 591.5Sjsm * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 601.5Sjsm * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 611.5Sjsm * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 621.5Sjsm */ 631.5Sjsm 641.4Schristos#include <sys/cdefs.h> 651.2Smycroft#ifndef lint 661.5Sjsm__RCSID("$NetBSD: alloc.c,v 1.5 2003/04/02 18:36:33 jsm Exp $"); 671.4Schristos#endif /* not lint */ 681.4Schristos 691.4Schristos#include <stdlib.h> 701.4Schristos#include "hack.h" 711.4Schristos#include "extern.h" 721.2Smycroft 731.1Scgd#ifdef LINT 741.1Scgd 751.1Scgd/* 761.1Scgd a ridiculous definition, suppressing 771.1Scgd "possible pointer alignment problem" for (long *) malloc() 781.1Scgd "enlarg defined but never used" 791.1Scgd "ftell defined (in <stdio.h>) but never used" 801.1Scgd from lint 811.1Scgd*/ 821.1Scgdlong * 831.4Schristosalloc(n) 841.4Schristos unsigned n; 851.4Schristos{ 861.4Schristos long dummy = ftell(stderr); 871.4Schristos if (n) 881.4Schristos dummy = 0; /* make sure arg is used */ 891.4Schristos return (&dummy); 901.1Scgd} 911.1Scgd 921.1Scgd#else 931.1Scgd 941.1Scgdlong * 951.1Scgdalloc(lth) 961.4Schristos unsigned lth; 971.1Scgd{ 981.4Schristos char *ptr; 991.1Scgd 1001.4Schristos if (!(ptr = malloc(lth))) 1011.1Scgd panic("Cannot get %d bytes", lth); 1021.4Schristos return ((long *) ptr); 1031.1Scgd} 1041.1Scgd 1051.1Scgdlong * 1061.4Schristosenlarge(ptr, lth) 1071.4Schristos char *ptr; 1081.4Schristos unsigned lth; 1091.1Scgd{ 1101.4Schristos char *nptr; 1111.1Scgd 1121.4Schristos if (!(nptr = realloc(ptr, lth))) 1131.1Scgd panic("Cannot reallocate %d bytes", lth); 1141.4Schristos return ((long *) nptr); 1151.1Scgd} 1161.1Scgd 1171.4Schristos#endif /* LINT */ 118