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.
20 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include "../slapd/slap.h"
27 * Just like malloc, except we check the returned value and exit
28 * if anything goes wrong.
37 if ( (new = (char *) malloc( size )) == NULL ) {
38 fprintf( stderr, "malloc of %d bytes failed\n", size );
49 * Just like realloc, except we check the returned value and exit
50 * if anything goes wrong.
60 if ( block == NULL ) {
61 return( ch_malloc( size ) );
64 if ( (new = (char *) realloc( block, size )) == NULL ) {
65 fprintf( stderr, "realloc of %d bytes failed\n", size );
76 * Just like calloc, except we check the returned value and exit
77 * if anything goes wrong.
87 if ( (new = (char *) calloc( nelem, size )) == NULL ) {
88 fprintf( stderr, "calloc of %d elems of %d bytes failed\n",
98 * Just like free, except we check to see if p is null.