2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2004 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
15 /* Portions Copyright (c) 1996 Regents of the University of Michigan.
16 * All rights reserved.
18 * Redistribution and use in source and binary forms are permitted
19 * provided that this notice is preserved and that due credit is given
20 * to the University of Michigan at Ann Arbor. The name of the University
21 * may not be used to endorse or promote products derived from this
22 * software without specific prior written permission. This software
23 * is provided ``as is'' without express or implied warranty.
26 * This work was originally developed by the University of Michigan
27 * (as part of U-MICH LDAP).
33 * ch_malloc.c - malloc() and friends, with check for NULL return.
40 #include <ac/stdlib.h>
41 #include <ac/socket.h>
43 #include "../slapd/slap.h"
49 * Just like malloc, except we check the returned value and exit
50 * if anything goes wrong.
59 if ( (new = (void *) ber_memalloc( size )) == NULL ) {
60 fprintf( stderr, "malloc of %lu bytes failed\n",
72 * Just like realloc, except we check the returned value and exit
73 * if anything goes wrong.
83 if ( block == NULL ) {
84 return( ch_malloc( size ) );
91 if ( (new = (void *) ber_memrealloc( block, size )) == NULL ) {
92 fprintf( stderr, "realloc of %lu bytes failed\n",
104 * Just like calloc, except we check the returned value and exit
105 * if anything goes wrong.
115 if ( (new = (void *) ber_memcalloc( nelem, size )) == NULL ) {
116 fprintf( stderr, "calloc of %lu elems of %lu bytes failed\n",
117 (long) nelem, (long) size );
118 exit( EXIT_FAILURE );
125 * Just like strdup, except we check the returned value and exit
126 * if anything goes wrong.
135 if ( (new = ber_strdup( string )) == NULL ) {
136 fprintf( stderr, "ch_strdup: duplication of \"%s\" failed\n",
138 exit( EXIT_FAILURE );
145 * Just like free, except we check to see if p is null.