2 * Copyright (c) 1996 Regents of the University of Michigan.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that this notice is preserved and that due credit is given
7 * to the University of Michigan at Ann Arbor. The name of the University
8 * may not be used to endorse or promote products derived from this
9 * software without specific prior written permission. This software
10 * is provided ``as is'' without express or implied warranty.
14 * ch_malloc.c - malloc() and friends, with check for NULL return.
22 #include <ac/socket.h>
24 #include "../slapd/slap.h"
29 * Just like malloc, except we check the returned value and exit
30 * if anything goes wrong.
39 if ( (new = (void *) malloc( size )) == NULL ) {
40 fprintf( stderr, "malloc of %lu bytes failed\n", size );
51 * Just like realloc, except we check the returned value and exit
52 * if anything goes wrong.
62 if ( block == NULL ) {
63 return( ch_malloc( size ) );
66 if ( (new = (void *) realloc( block, size )) == NULL ) {
67 fprintf( stderr, "realloc of %lu bytes failed\n", size );
78 * Just like calloc, except we check the returned value and exit
79 * if anything goes wrong.
89 if ( (new = (void *) calloc( nelem, size )) == NULL ) {
90 fprintf( stderr, "calloc of %lu elems of %lu bytes failed\n",
100 * Just like free, except we check to see if p is null.