]> git.sur5r.net Git - openldap/blob - servers/slapd/ch_malloc.c
Initial revision
[openldap] / servers / slapd / ch_malloc.c
1 /* ch_malloc.c - malloc routines that test returns from malloc and friends */
2
3 #include <stdio.h>
4 #include <sys/types.h>
5 #include <sys/socket.h>
6 #include "slap.h"
7
8 char *
9 ch_malloc(
10     unsigned long       size
11 )
12 {
13         char    *new;
14
15         if ( (new = (char *) malloc( size )) == NULL ) {
16                 Debug( LDAP_DEBUG_ANY, "malloc of %d bytes failed\n", size, 0, 0 );
17                 exit( 1 );
18         }
19
20         return( new );
21 }
22
23 char *
24 ch_realloc(
25     char                *block,
26     unsigned long       size
27 )
28 {
29         char    *new;
30
31         if ( block == NULL ) {
32                 return( ch_malloc( size ) );
33         }
34
35         if ( (new = (char *) realloc( block, size )) == NULL ) {
36                 Debug( LDAP_DEBUG_ANY, "realloc of %d bytes failed\n", size, 0, 0 );
37                 exit( 1 );
38         }
39
40         return( new );
41 }
42
43 char *
44 ch_calloc(
45     unsigned long       nelem,
46     unsigned long       size
47 )
48 {
49         char    *new;
50
51         if ( (new = (char *) calloc( nelem, size )) == NULL ) {
52                 Debug( LDAP_DEBUG_ANY, "calloc of %d elems of %d bytes failed\n",
53                   nelem, size, 0 );
54                 exit( 1 );
55         }
56
57         return( new );
58 }