From 733056970eb79ffebcd98f4eaf5b1362f4c5bc7c Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Wed, 26 Dec 2001 11:15:28 +0000 Subject: [PATCH] Changed ber_bvdup to ber_dupbv with destination provided --- include/lber.h | 6 ++++-- libraries/liblber/memory.c | 29 +++++++++++++++++------------ 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/include/lber.h b/include/lber.h index cd986f72b0..16447557bd 100644 --- a/include/lber.h +++ b/include/lber.h @@ -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(( diff --git a/libraries/liblber/memory.c b/libraries/liblber/memory.c index 0e8f4e071a..4766a21f23 100644 --- a/libraries/liblber/memory.c +++ b/libraries/liblber/memory.c @@ -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; } -- 2.39.5