File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / bird / lib / xmalloc.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Aug 22 12:33:54 2017 UTC (6 years, 10 months ago) by misho
Branches: bird, MAIN
CVS tags: v1_6_8p3, v1_6_3p0, v1_6_3, HEAD
bird 1.6.3

    1: /*
    2:  *	BIRD Library -- malloc() With Checking
    3:  *
    4:  *	(c) 1998--2000 Martin Mares <mj@ucw.cz>
    5:  *
    6:  *	Can be freely distributed and used under the terms of the GNU GPL.
    7:  */
    8: 
    9: #include <stdlib.h>
   10: 
   11: #include "nest/bird.h"
   12: #include "lib/resource.h"
   13: 
   14: #ifndef HAVE_LIBDMALLOC
   15: 
   16: /**
   17:  * xmalloc - malloc with checking
   18:  * @size: block size
   19:  *
   20:  * This function is equivalent to malloc() except that in case of
   21:  * failure it calls die() to quit the program instead of returning
   22:  * a %NULL pointer.
   23:  *
   24:  * Wherever possible, please use the memory resources instead.
   25:  */
   26: void *
   27: xmalloc(uint size)
   28: {
   29:   void *p = malloc(size);
   30:   if (p)
   31:     return p;
   32:   die("Unable to allocate %d bytes of memory", size);
   33: }
   34: 
   35: /**
   36:  * xrealloc - realloc with checking
   37:  * @ptr: original memory block
   38:  * @size: block size
   39:  *
   40:  * This function is equivalent to realloc() except that in case of
   41:  * failure it calls die() to quit the program instead of returning
   42:  * a %NULL pointer.
   43:  *
   44:  * Wherever possible, please use the memory resources instead.
   45:  */
   46: void *
   47: xrealloc(void *ptr, uint size)
   48: {
   49:   void *p = realloc(ptr, size);
   50:   if (p)
   51:     return p;
   52:   die("Unable to allocate %d bytes of memory", size);
   53: }
   54: 
   55: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>