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.
16 * ch_malloc.c - malloc() and friends, with check for NULL return.
23 #include <ac/stdlib.h>
24 #include <ac/socket.h>
26 #include "../slapd/slap.h"
32 * Just like malloc, except we check the returned value and exit
33 * if anything goes wrong.
42 if ( (new = (void *) ber_memalloc( size )) == NULL ) {
43 fprintf( stderr, "malloc of %lu bytes failed\n",
55 * Just like realloc, except we check the returned value and exit
56 * if anything goes wrong.
66 if ( block == NULL ) {
67 return( ch_malloc( size ) );
74 if ( (new = (void *) ber_memrealloc( block, size )) == NULL ) {
75 fprintf( stderr, "realloc of %lu bytes failed\n",
87 * Just like calloc, except we check the returned value and exit
88 * if anything goes wrong.
98 if ( (new = (void *) ber_memcalloc( nelem, size )) == NULL ) {
99 fprintf( stderr, "calloc of %lu elems of %lu bytes failed\n",
100 (long) nelem, (long) size );
101 exit( EXIT_FAILURE );
109 * Just like free, except we check to see if p is null.