diff options
author | Andrew Tridgell <tridge@samba.org> | 2009-04-09 14:28:38 +1000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2009-04-09 14:28:38 +1000 |
commit | fd7c52231fc4ca6e4ad2a72955a053f321cb0fb4 (patch) | |
tree | a92ed93fc378ca9809acfa47f9899242b3405a3e /lib/util | |
parent | 26f5225ae2c75103147f15f953ef3dbc2b403399 (diff) | |
download | samba-fd7c52231fc4ca6e4ad2a72955a053f321cb0fb4.tar.gz samba-fd7c52231fc4ca6e4ad2a72955a053f321cb0fb4.tar.bz2 samba-fd7c52231fc4ca6e4ad2a72955a053f321cb0fb4.zip |
added _const versions of some of the str_list_*() functions
These const versions don't copy the strings themselves, which
is useful when those strings point at known constant data (into the
schema in this case)
Diffstat (limited to 'lib/util')
-rw-r--r-- | lib/util/util.h | 20 | ||||
-rw-r--r-- | lib/util/util_strlist.c | 64 |
2 files changed, 84 insertions, 0 deletions
diff --git a/lib/util/util.h b/lib/util/util.h index 78fc87ebe1..81c7edfbdf 100644 --- a/lib/util/util.h +++ b/lib/util/util.h @@ -468,6 +468,26 @@ _PUBLIC_ char **str_list_unique(char **list); */ _PUBLIC_ void str_list_show(const char **list); + +/** + append one list to another - expanding list1 + this assumes the elements of list2 are const pointers, so we can re-use them +*/ +_PUBLIC_ char **str_list_append_const(char **list1, const char **list2); + +/** + add an entry to a string list + this assumes s will not change +*/ +_PUBLIC_ char **str_list_add_const(char **list, const char *s); + +/** + copy a string list + this assumes list will not change +*/ +_PUBLIC_ char **str_list_copy_const(TALLOC_CTX *mem_ctx, const char **list); + + /* 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 29556b14d0..bd7bd00888 100644 --- a/lib/util/util_strlist.c +++ b/lib/util/util_strlist.c @@ -377,3 +377,67 @@ _PUBLIC_ void str_list_show(const char **list) DEBUG(0,("}\n")); } + + +/** + append one list to another - expanding list1 + this assumes the elements of list2 are const pointers, so we can re-use them +*/ +_PUBLIC_ char **str_list_append_const(char **list1, const char **list2) +{ + size_t len1 = str_list_length(list1); + size_t len2 = str_list_length(list2); + char **ret; + int i; + + ret = talloc_realloc(NULL, list1, char *, len1+len2+1); + if (ret == NULL) return NULL; + + for (i=len1;i<len1+len2;i++) { + ret[i] = list2[i-len1]; + } + ret[i] = NULL; + + return ret; +} + +/** + add an entry to a string list + this assumes s will not change +*/ +_PUBLIC_ char **str_list_add_const(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] = s; + ret[len+1] = NULL; + + return ret; +} + +/** + copy a string list + this assumes list will not change +*/ +_PUBLIC_ char **str_list_copy_const(TALLOC_CTX *mem_ctx, const char **list) +{ + int i; + char **ret; + + if (list == NULL) + return NULL; + + ret = talloc_array(mem_ctx, char *, str_list_length(list)+1); + if (ret == NULL) + return NULL; + + for (i=0;list && list[i];i++) { + ret[i] = list[i]; + } + ret[i] = NULL; + return ret; +} |