util: move add_gid_to_array_unique to toplevel and add add_uid_to_array_unique.
[ira/wip.git] / lib / util / util.h
index defef127d93e4f162a8d2186a5a4ca6f40cf939b..20050d2f0a6929c19823420cdcb0c3d9399accca 100644 (file)
@@ -396,6 +396,16 @@ _PUBLIC_ bool strequal(const char *s1, const char *s2);
 #define LIST_SEP " \t,\n\r"
 #endif
 
+/**
+  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);
+
+/**
+  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);
+
 /**
   build a null terminated list of strings from a input string and a
   separator list. The separator list must contain characters less than
@@ -453,6 +463,42 @@ _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(const char **list1, const char * const *list2);
+
+/**
+ remove duplicate elements from a list 
+*/
+_PUBLIC_ const char **str_list_unique(const char **list);
+
+/*
+  very useful when debugging complex list related code
+ */
+_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_ const char **str_list_append_const(const char **list1,
+                                           const char **list2);
+
+/**
+  add an entry to a string list
+  this assumes s will not change
+*/
+_PUBLIC_ const char **str_list_add_const(const char **list, const char *s);
+
+/**
+  copy a string list
+  this assumes list will not change
+*/
+_PUBLIC_ const char **str_list_copy_const(TALLOC_CTX *mem_ctx,
+                                         const char **list);
+
 
 /* The following definitions come from lib/util/util_file.c  */
 
@@ -771,4 +817,16 @@ bool unmap_file(void *start, size_t size);
 
 void print_asc(int level, const uint8_t *buf,int len);
 
+/**
+ * Add an id to an array of ids.
+ *
+ * num should be a pointer to an integer that holds the current
+ * number of elements in ids. It will be updated by this function.
+ */
+
+bool add_uid_to_array_unique(TALLOC_CTX *mem_ctx, uid_t uid,
+                            uid_t **uids, size_t *num_uids);
+bool add_gid_to_array_unique(TALLOC_CTX *mem_ctx, gid_t gid,
+                            gid_t **gids, size_t *num_gids);
+
 #endif /* _SAMBA_UTIL_H_ */