emalloc.c revision 285830
11145Ssundar/*
21138Ssundar * Copyright (c) 1999 - 2001 Kungliga Tekniska H��gskolan
31138Ssundar * (Royal Institute of Technology, Stockholm, Sweden).
41138Ssundar * All rights reserved.
51138Ssundar *
61138Ssundar * Redistribution and use in source and binary forms, with or without
71138Ssundar * modification, are permitted provided that the following conditions
81138Ssundar * are met:
91138Ssundar *
101138Ssundar * 1. Redistributions of source code must retain the above copyright
111138Ssundar *    notice, this list of conditions and the following disclaimer.
121138Ssundar *
131138Ssundar * 2. Redistributions in binary form must reproduce the above copyright
141138Ssundar *    notice, this list of conditions and the following disclaimer in the
151138Ssundar *    documentation and/or other materials provided with the distribution.
161138Ssundar *
171138Ssundar * 3. Neither the name of the Institute nor the names of its contributors
181138Ssundar *    may be used to endorse or promote products derived from this software
191138Ssundar *    without specific prior written permission.
201138Ssundar *
211138Ssundar * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
221138Ssundar * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231138Ssundar * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241138Ssundar * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
251138Ssundar * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261138Ssundar * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271138Ssundar * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281138Ssundar * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291138Ssundar * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301138Ssundar * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311138Ssundar * SUCH DAMAGE.
321138Ssundar */
331138Ssundar
341138Ssundar#include <config.h>
351145Ssundar
361138Ssundar#include <stdlib.h>
371138Ssundar#include <err.h>
381138Ssundar
391138Ssundar#include "roken.h"
401138Ssundar
411138Ssundar/*
421138Ssundar * Like malloc but never fails.
431138Ssundar */
441138Ssundar
451138SsundarROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL
461364Smhauptemalloc (size_t sz)
471138Ssundar{
481138Ssundar    void *tmp = malloc (sz);
491138Ssundar
501138Ssundar    if (tmp == NULL && sz != 0)
511138Ssundar	errx (1, "malloc %lu failed", (unsigned long)sz);
521138Ssundar    return tmp;
531138Ssundar}
541138Ssundar