Add new functions and tests: str_list_make_empty(), str_list_make_single()
[sfrench/samba-autobuild/.git] / lib / util / util_strlist.c
index 6936f189aada2a9e51085ca57de0c925fdb36845..2fcbe186be081ec3b2b940b73673a72fcf828d88 100644 (file)
  * @brief String list manipulation
  */
 
+/**
+  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