Changed ber_bvdup to ber_dupbv with destination provided

This commit is contained in:
Howard Chu 2001-12-26 11:15:28 +00:00
parent fb3af1ccbd
commit 733056970e
2 changed files with 21 additions and 14 deletions

View 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((

View 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;
}