1 /* charray.c - routines for dealing with char * arrays */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/string.h>
13 #include <ac/socket.h>
26 *a = (char **) ch_malloc( 2 * sizeof(char *) );
29 for ( n = 0; *a != NULL && (*a)[n] != NULL; n++ ) {
33 *a = (char **) ch_realloc( (char *) *a,
34 (n + 2) * sizeof(char *) );
37 (*a)[n++] = ch_strdup(s);
49 for ( n = 0; *a != NULL && (*a)[n] != NULL; n++ ) {
52 for ( nn = 0; s[nn] != NULL; nn++ ) {
56 *a = (char **) ch_realloc( (char *) *a, (n + nn + 1) * sizeof(char *) );
58 for ( i = 0; i < nn; i++ ) {
59 (*a)[n + i] = ch_strdup(s[i]);
65 charray_free( char **array )
69 if ( array == NULL ) {
73 for ( a = array; *a != NULL; a++ ) {
78 free( (char *) array );
89 for ( i = 0; a[i] != NULL; i++ ) {
90 if ( strcasecmp( s, a[i] ) == 0 ) {
99 charray_dup( char **a )
104 for ( i = 0; a[i] != NULL; i++ )
107 new = (char **) ch_malloc( (i + 1) * sizeof(char *) );
109 for ( i = 0; a[i] != NULL; i++ ) {
110 new[i] = ch_strdup( a[i] );
119 str2charray( const char *str_in, const char *brkstr )
127 /* protect the input string from strtok */
128 str = ch_strdup( str_in );
131 for ( s = str; *s; s++ ) {
132 if ( strchr( brkstr, *s ) != NULL ) {
137 res = (char **) ch_malloc( (i + 1) * sizeof(char *) );
140 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
142 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
144 res[i++] = ch_strdup( s );