]> git.sur5r.net Git - openldap/commitdiff
Changed ber_bvdup to ber_dupbv with destination provided
authorHoward Chu <hyc@openldap.org>
Wed, 26 Dec 2001 11:15:28 +0000 (11:15 +0000)
committerHoward Chu <hyc@openldap.org>
Wed, 26 Dec 2001 11:15:28 +0000 (11:15 +0000)
include/lber.h
libraries/liblber/memory.c

index cd986f72b03578f90ac1666c53fce23141fd8f34..16447557bd2fd2900874e125ab2a213bc49f5101 100644 (file)
@@ -545,8 +545,10 @@ ber_bvecadd LDAP_P((
        struct berval *bv ));
 
 LBER_F( struct berval * )
-ber_bvdup LDAP_P((
-       LDAP_CONST struct berval *bv ));
+ber_dupbv LDAP_P((
+       struct berval *dst, LDAP_CONST struct berval *src ));
+
+#define        ber_bvdup(bv)   ber_dupbv(NULL, bv)
 
 LBER_F( struct berval * )
 ber_str2bv LDAP_P((
index 0e8f4e071a437b0a44e6b3bec2aa4cca0fe17223..4766a21f23addd7f27d8f8ad09ce056e1c864793 100644 (file)
@@ -446,38 +446,43 @@ ber_bvecadd( struct berval ***bvec, struct berval *bv )
 
 
 struct berval *
-ber_bvdup(
-       LDAP_CONST struct berval *bv )
+ber_dupbv(
+       struct berval *dst, LDAP_CONST struct berval *src )
 {
        struct berval *new;
 
        ber_int_options.lbo_valid = LBER_INITIALIZED;
 
-       if( bv == NULL ) {
+       if( src == NULL ) {
                ber_errno = LBER_ERROR_PARAM;
                return NULL;
        }
 
-       if(( new = LBER_MALLOC( sizeof(struct berval) )) == NULL ) {
-               ber_errno = LBER_ERROR_MEMORY;
-               return NULL;
+       if ( dst ) {
+               new = dst;
+       } else {
+               if(( new = LBER_MALLOC( sizeof(struct berval) )) == NULL ) {
+                       ber_errno = LBER_ERROR_MEMORY;
+                       return NULL;
+               }
        }
 
-       if ( bv->bv_val == NULL ) {
+       if ( src->bv_val == NULL ) {
                new->bv_val = NULL;
                new->bv_len = 0;
                return new;
        }
 
-       if(( new->bv_val = LBER_MALLOC( bv->bv_len + 1 )) == NULL ) {
+       if(( new->bv_val = LBER_MALLOC( src->bv_len + 1 )) == NULL ) {
                ber_errno = LBER_ERROR_MEMORY;
-               LBER_FREE( new );
+               if ( !dst )
+                       LBER_FREE( new );
                return NULL;
        }
 
-       AC_MEMCPY( new->bv_val, bv->bv_val, bv->bv_len );
-       new->bv_val[bv->bv_len] = '\0';
-       new->bv_len = bv->bv_len;
+       AC_MEMCPY( new->bv_val, src->bv_val, src->bv_len );
+       new->bv_val[src->bv_len] = '\0';
+       new->bv_len = src->bv_len;
 
        return new;
 }