From: Kurt Zeilenga Date: Fri, 17 Dec 1999 05:37:33 +0000 (+0000) Subject: Add ber_bvstr and ber_bvstrdup string to berval allocators. X-Git-Tag: UCDATA_2_4~77 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=37d28e7d0d7e758a77f4dd655980d9a32efdada5;p=openldap Add ber_bvstr and ber_bvstrdup string to berval allocators. --- diff --git a/include/lber.h b/include/lber.h index be36e58bb4..12a152f141 100644 --- a/include/lber.h +++ b/include/lber.h @@ -470,6 +470,14 @@ LIBLBER_F( struct berval * ) ber_bvdup LDAP_P(( LDAP_CONST struct berval *bv )); +LIBLBER_F( struct berval * ) +ber_bvstr LDAP_P(( + LDAP_CONST char * )); + +LIBLBER_F( struct berval * ) +ber_bvstrdup LDAP_P(( + LDAP_CONST char * )); + LIBLBER_F( char * ) ber_strdup LDAP_P(( LDAP_CONST char * )); diff --git a/include/ldap_cdefs.h b/include/ldap_cdefs.h index 85de679335..9c7b953f7b 100644 --- a/include/ldap_cdefs.h +++ b/include/ldap_cdefs.h @@ -118,7 +118,7 @@ # define LIBLUTIL_F(type) extern type #endif -/* SLAPD (as a module exporting symbols */ +/* SLAPD (as a module exporting symbols) */ #if defined(LIBSLAPD_DECL) && defined(_WIN32) # define LIBSLAPD_F(type) extern __declspec(LIBSLAPD_DECL) type #else diff --git a/libraries/liblber/memory.c b/libraries/liblber/memory.c index d45a09d0ad..327cff2997 100644 --- a/libraries/liblber/memory.c +++ b/libraries/liblber/memory.c @@ -292,6 +292,66 @@ ber_bvdup( return( new ); } +struct berval * +ber_bvstr( + LDAP_CONST char *s ) +{ + struct berval *new; + + ber_int_options.lbo_valid = LBER_INITIALIZED; + + if( s == NULL ) { + ber_errno = LBER_ERROR_PARAM; + return NULL; + } + + if(( new = LBER_MALLOC( sizeof(struct berval) )) == NULL ) { + ber_errno = LBER_ERROR_MEMORY; + return NULL; + } + + if ( *s == '\0' ) { + new->bv_val = NULL; + new->bv_len = 0; + return new; + } + + new->bv_val = (char *) s; + new->bv_len = strlen( s ); + + return( new ); +} + +struct berval * +ber_bvstrdup( + LDAP_CONST char *s ) +{ + struct berval *new; + char *p; + + ber_int_options.lbo_valid = LBER_INITIALIZED; + + if( s == NULL ) { + ber_errno = LBER_ERROR_PARAM; + return NULL; + } + + p = LBER_STRDUP( s ); + + if( p == NULL ) { + ber_errno = LBER_ERROR_MEMORY; + return NULL; + } + + new = ber_bvstr( p ); + + if( new == NULL || *p == '\0' ) { + LBER_FREE( p ); + } + + return( new ); +} + char * ber_strdup( LDAP_CONST char *s ) {