From 016328a1da46c975e6d9603b65947d792f4e1e64 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Fri, 6 Jul 2001 12:20:26 +0000 Subject: [PATCH] added misc charray utilities --- servers/slapd/charray.c | 62 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/servers/slapd/charray.c b/servers/slapd/charray.c index b51659141a..c8790791be 100644 --- a/servers/slapd/charray.c +++ b/servers/slapd/charray.c @@ -38,6 +38,33 @@ charray_add( (*a)[n] = NULL; } +void +charray_add_n( + char ***a, + const char *s, + int l +) +{ + int n; + + if ( *a == NULL ) { + *a = (char **) ch_malloc( 2 * sizeof(char *) ); + n = 0; + } else { + for ( n = 0; *a != NULL && (*a)[n] != NULL; n++ ) { + ; /* NULL */ + } + + *a = (char **) ch_realloc( (char *) *a, + (n + 2) * sizeof(char *) ); + } + + (*a)[n] = (char *) ch_malloc( ( l + 1 ) * sizeof( char ) ); + strncpy( (*a)[n], s, l ); + (*a)[n][l] = '\0'; + (*a)[++n] = NULL; +} + void charray_merge( char ***a, @@ -151,3 +178,38 @@ str2charray( const char *str_in, const char *brkstr ) free( str ); return( res ); } + + +int +charray_strcmp( const char **a1, const char **a2 ) +{ + for ( ; a1[0] && a2[0]; a1++, a2++ ) { + if ( strcmp( a1[0], a2[0] ) ) { + return( !0 ); + } + } + + if ( ! ( a1[0] && a2[0] ) ) { + return( !0 ); + } + + return 0; +} + + +int +charray_strcasecmp( const char **a1, const char **a2 ) +{ + for ( ; a1[0] && a2[0]; a1++, a2++ ) { + if ( strcasecmp( a1[0], a2[0] ) ) { + return( !0 ); + } + } + + if ( ! ( a1[0] && a2[0] ) ) { + return( !0 ); + } + + return 0; +} + -- 2.39.5