From 2f877b48b197f5478db44a4faff7d7be78281ab0 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Thu, 21 Apr 2005 03:40:50 +0000 Subject: [PATCH] introduce ber_bvreplace() --- include/lber.h | 4 ++++ include/lber_pvt.h | 4 ++++ libraries/liblber/memory.c | 25 +++++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/include/lber.h b/include/lber.h index c3c0da6485..93eebc3e48 100644 --- a/include/lber.h +++ b/include/lber.h @@ -597,6 +597,10 @@ LBER_F( char * ) ber_strdup LDAP_P(( LDAP_CONST char * )); +LBER_F( struct berval * ) +ber_bvreplace LDAP_P(( + struct berval *dst, LDAP_CONST struct berval *src )); + LBER_F( void ) ber_bvarray_free LDAP_P(( BerVarray p )); diff --git a/include/lber_pvt.h b/include/lber_pvt.h index a23f33f9c3..6fd557d230 100644 --- a/include/lber_pvt.h +++ b/include/lber_pvt.h @@ -135,6 +135,10 @@ LBER_F( char * ) ber_strdup_x LDAP_P(( LDAP_CONST char *, void *ctx )); +LBER_F( struct berval * ) +ber_bvreplace_x LDAP_P(( + struct berval *dst, LDAP_CONST struct berval *src, void *ctx )); + LBER_F( void ) ber_bvarray_free_x LDAP_P(( BerVarray p, void *ctx )); diff --git a/libraries/liblber/memory.c b/libraries/liblber/memory.c index ea96e2d6ce..5b4089fec2 100644 --- a/libraries/liblber/memory.c +++ b/libraries/liblber/memory.c @@ -713,6 +713,31 @@ ber_strndup( LDAP_CONST char *s, ber_len_t l ) return ber_strndup_x( s, l, NULL ); } +/* + * dst is resized as required by src and the value of src is copied into dst + * dst->bv_val must be NULL (and dst->bv_len must be 0), or it must be + * alloc'ed with the context ctx + */ +struct berval * +ber_bvreplace_x( struct berval *dst, LDAP_CONST struct berval *src, void *ctx ) +{ + assert( dst != NULL ); + + if ( dst->bv_len < src->bv_len ) { + dst->bv_val = ber_memrealloc_x( dst->bv_val, src->bv_len + 1, ctx ); + } + + AC_MEMCPY( dst->bv_val, src->bv_val, src->bv_len + 1 ); + + return dst; +} + +struct berval * +ber_bvreplace( struct berval *dst, LDAP_CONST struct berval *src ) +{ + return ber_bvreplace_x( dst, src, NULL ); +} + void ber_bvarray_free_x( BerVarray a, void *ctx ) { -- 2.39.5