diff options
author | Andrew Bartlett <abartlet@samba.org> | 2009-05-13 16:49:34 +1000 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2009-05-14 05:56:58 +1000 |
commit | a89bee4c98819567c6e15c0cae32372e32e118f5 (patch) | |
tree | ac92b6ff91a4601526047f574b3bc743a4fb4f11 /lib/util/util_strlist.c | |
parent | a13ba4347f92afc63497991210bc59e6bd2434d0 (diff) | |
download | samba-a89bee4c98819567c6e15c0cae32372e32e118f5.tar.gz samba-a89bee4c98819567c6e15c0cae32372e32e118f5.tar.bz2 samba-a89bee4c98819567c6e15c0cae32372e32e118f5.zip |
Add new functions and tests: str_list_make_empty(), str_list_make_single()
Diffstat (limited to 'lib/util/util_strlist.c')
-rw-r--r-- | lib/util/util_strlist.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/util/util_strlist.c b/lib/util/util_strlist.c index 6936f189aa..2fcbe186be 100644 --- a/lib/util/util_strlist.c +++ b/lib/util/util_strlist.c @@ -29,6 +29,47 @@ */ /** + build an empty (only NULL terminated) list of strings (for expansion with str_list_add() etc) +*/ +_PUBLIC_ char **str_list_make_empty(TALLOC_CTX *mem_ctx) +{ + int num_elements = 0; + char **ret = NULL; + + ret = talloc_array(mem_ctx, char *, 1); + if (ret == NULL) { + return NULL; + } + + ret[0] = NULL; + + return ret; +} + +/** + place the only element 'entry' into a new, NULL terminated string list +*/ +_PUBLIC_ char **str_list_make_single(TALLOC_CTX *mem_ctx, const char *entry) +{ + int num_elements = 0; + char **ret = NULL; + + ret = talloc_array(mem_ctx, char *, 2); + if (ret == NULL) { + return NULL; + } + + ret[0] = talloc_strdup(ret, entry); + if (!ret[0]) { + talloc_free(ret); + return NULL; + } + ret[1] = NULL; + + return ret; +} + +/** build a null terminated list of strings from a input string and a separator list. The separator list must contain characters less than or equal to 0x2f for this to work correctly on multi-byte strings |