]> git.sur5r.net Git - openldap/blob - servers/slapd/ch_malloc.c
Axe <varargs.h> support: Don't use LDAP_P() on varargs prototype.
[openldap] / servers / slapd / ch_malloc.c
1 /* ch_malloc.c - malloc routines that test returns from malloc and friends */
2 /*
3  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6
7 #define CH_FREE 1
8
9 #include "portable.h"
10
11 #include <stdio.h>
12
13 #include <ac/stdlib.h>
14
15 #include <ac/string.h>
16 #include <ac/socket.h>
17
18 #include "slap.h"
19
20 #ifndef CSRIMALLOC
21
22 void *
23 ch_malloc(
24     ber_len_t   size
25 )
26 {
27         void    *new;
28
29         if ( (new = (void *) ber_memalloc( size )) == NULL ) {
30                 Debug( LDAP_DEBUG_ANY, "ch_malloc of %lu bytes failed\n",
31                         (long) size, 0, 0 );
32                 assert( 0 );
33                 exit( EXIT_FAILURE );
34         }
35
36         return( new );
37 }
38
39 void *
40 ch_realloc(
41     void                *block,
42     ber_len_t   size
43 )
44 {
45         void    *new;
46
47         if ( block == NULL ) {
48                 return( ch_malloc( size ) );
49         }
50
51         if( size == 0 ) {
52                 ch_free( block );
53         }
54
55         if ( (new = (void *) ber_memrealloc( block, size )) == NULL ) {
56                 Debug( LDAP_DEBUG_ANY, "ch_realloc of %lu bytes failed\n",
57                         (long) size, 0, 0 );
58                 assert( 0 );
59                 exit( EXIT_FAILURE );
60         }
61
62         return( new );
63 }
64
65 void *
66 ch_calloc(
67     ber_len_t   nelem,
68     ber_len_t   size
69 )
70 {
71         void    *new;
72
73         if ( (new = (void *) ber_memcalloc( nelem, size )) == NULL ) {
74                 Debug( LDAP_DEBUG_ANY, "ch_calloc of %lu elems of %lu bytes failed\n",
75                   (long) nelem, (long) size, 0 );
76                 assert( 0 );
77                 exit( EXIT_FAILURE );
78         }
79
80         return( new );
81 }
82
83 char *
84 ch_strdup(
85     const char *string
86 )
87 {
88         char    *new;
89
90         if ( (new = ber_strdup( string )) == NULL ) {
91                 Debug( LDAP_DEBUG_ANY, "ch_strdup(%s) failed\n", string, 0, 0 );
92                 assert( 0 );
93                 exit( EXIT_FAILURE );
94         }
95
96         return( new );
97 }
98
99 void
100 ch_free( void *ptr )
101 {
102         ber_memfree( ptr );
103 }
104
105 #endif