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