X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fcharray.c;h=b40e232f62c6afef4458d1777f4f706adbf83022;hb=b0b8546f054f31b1a080defede171f833d20b124;hp=744ab07b7397c8966f213297ee1781e0ae220173;hpb=29d9fa20a2823c827f098d78f1ea8539d86bf4cf;p=openldap diff --git a/libraries/libldap/charray.c b/libraries/libldap/charray.c index 744ab07b73..b40e232f62 100644 --- a/libraries/libldap/charray.c +++ b/libraries/libldap/charray.c @@ -1,6 +1,6 @@ /* $OpenLDAP$ */ /* - * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved. + * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved. * COPYING RESTRICTIONS APPLY, see COPYRIGHT file */ /* charray.c - routines for dealing with char * arrays */ @@ -77,8 +77,9 @@ ldap_charray_merge( aa = (char **) LDAP_REALLOC( (char *) *a, (n + nn + 1) * sizeof(char *) ); - if( aa == NULL ) + if( aa == NULL ) { return -1; + } *a = aa; @@ -217,3 +218,47 @@ ldap_str2charray( const char *str_in, const char *brkstr ) LDAP_FREE( str ); return( res ); } + +char * ldap_charray2str( char **a, const char *sep ) +{ + char *s, **v, *p; + int len; + int slen; + + if( sep == NULL ) sep = " "; + + slen = strlen( sep ); + len = 0; + + for ( v = a; *v != NULL; v++ ) { + len += strlen( *v ) + slen; + } + + if ( len == 0 ) { + return NULL; + } + + /* trim extra sep len */ + len -= slen; + + s = LDAP_MALLOC ( len + 1 ); + + if ( s == NULL ) { + return NULL; + } + + p = s; + for ( v = a; *v != NULL; v++ ) { + if ( v != a ) { + strncpy( p, sep, slen ); + p += slen; + } + + len = strlen( *v ); + strncpy( p, *v, len ); + p += len; + } + + *p = '\0'; + return s; +}