summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2009-04-08 23:18:13 +1000
committerAndrew Bartlett <abartlet@samba.org>2009-04-08 23:18:13 +1000
commit54f7523db1848d75f61a8f02968de30bd6c49804 (patch)
tree33b8d5f82ee98e93dd979e201e67ac662f302ebb /lib
parent217628f88119d1cadfa88dbfd57d0e9e94693838 (diff)
downloadsamba-54f7523db1848d75f61a8f02968de30bd6c49804.tar.gz
samba-54f7523db1848d75f61a8f02968de30bd6c49804.tar.bz2
samba-54f7523db1848d75f61a8f02968de30bd6c49804.zip
Rework util_strlist prototypes to use a bit more and less const
Hopefully this produces less warnings, but it might produce more... Andrew Bartlett
Diffstat (limited to 'lib')
-rw-r--r--lib/util/util.h13
-rw-r--r--lib/util/util_strlist.c39
2 files changed, 43 insertions, 9 deletions
diff --git a/lib/util/util.h b/lib/util/util.h
index defef127d9..bb07180872 100644
--- a/lib/util/util.h
+++ b/lib/util/util.h
@@ -427,7 +427,7 @@ _PUBLIC_ size_t str_list_length(const char * const *list);
/**
copy a string list
*/
-_PUBLIC_ char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list);
+_PUBLIC_ char **str_list_copy(TALLOC_CTX *mem_ctx, const char * const *list);
/**
Return true if all the elements of the list match exactly.
@@ -437,7 +437,12 @@ _PUBLIC_ bool str_list_equal(const char **list1, const char **list2);
/**
add an entry to a string list
*/
-_PUBLIC_ const char **str_list_add(const char **list, const char *s);
+_PUBLIC_ char **str_list_add(char **list, const char *s);
+
+/**
+ add an entry to a string list (if not already in there)
+*/
+_PUBLIC_ char **str_list_add_unique(char **list, const char *s);
/**
remove an entry from a string list
@@ -453,6 +458,10 @@ _PUBLIC_ bool str_list_check(const char **list, const char *s);
return true if a string is in a list, case insensitively
*/
_PUBLIC_ bool str_list_check_ci(const char **list, const char *s);
+/**
+ append one list to another - expanding list1
+*/
+_PUBLIC_ char **str_list_append(char **list1, const char * const *list2);
/* The following definitions come from lib/util/util_file.c */
diff --git a/lib/util/util_strlist.c b/lib/util/util_strlist.c
index c53fee8f82..86956289b4 100644
--- a/lib/util/util_strlist.c
+++ b/lib/util/util_strlist.c
@@ -198,7 +198,7 @@ _PUBLIC_ size_t str_list_length(const char * const*list)
/**
copy a string list
*/
-_PUBLIC_ char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list)
+_PUBLIC_ char **str_list_copy(TALLOC_CTX *mem_ctx, const char * const *list)
{
int i;
char **ret;
@@ -245,13 +245,19 @@ _PUBLIC_ bool str_list_equal(const char **list1, const char **list2)
/**
- add an entry to a string list
+ add an entry to a string list if not already in there
*/
-_PUBLIC_ const char **str_list_add(const char **list, const char *s)
+_PUBLIC_ char **str_list_add_unique(char **list, const char *s)
{
- size_t len = str_list_length(list);
+ int i;
+ size_t len;
const char **ret;
+ for (i=0;list[i];i++) {
+ if (strcmp(list[i], s) == 0) return list;
+ }
+
+ len = i;
ret = talloc_realloc(NULL, list, const char *, len+2);
if (ret == NULL) return NULL;
@@ -264,6 +270,25 @@ _PUBLIC_ const char **str_list_add(const char **list, const char *s)
}
/**
+ add an entry to a string list
+*/
+_PUBLIC_ char **str_list_add(char **list, const char *s)
+{
+ size_t len = str_list_length(list);
+ char **ret;
+
+ ret = talloc_realloc(NULL, list, char *, len+2);
+ if (ret == NULL) return NULL;
+
+ ret[len] = talloc_strdup(ret, s);
+ if (ret[len] == NULL) return NULL;
+
+ ret[len+1] = NULL;
+
+ return ret;
+}
+
+/**
remove an entry from a string list
*/
_PUBLIC_ void str_list_remove(const char **list, const char *s)
@@ -311,14 +336,14 @@ _PUBLIC_ bool str_list_check_ci(const char **list, const char *s)
/**
append one list to another - expanding list1
*/
-_PUBLIC_ const char **str_list_append(const char **list1, const char **list2)
+_PUBLIC_ char **str_list_append(char **list1, const char * const *list2)
{
size_t len1 = str_list_length(list1);
size_t len2 = str_list_length(list2);
- const char **ret;
+ char **ret;
int i;
- ret = talloc_realloc(NULL, list1, const char *, len1+len2+1);
+ ret = talloc_realloc(NULL, list1, char *, len1+len2+1);
if (ret == NULL) return NULL;
for (i=len1;i<len1+len2;i++) {