summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorLuke Leighton <lkcl@samba.org>1999-11-12 15:37:05 +0000
committerLuke Leighton <lkcl@samba.org>1999-11-12 15:37:05 +0000
commit4c479f0574019afb2fc8a3dbfc802c75fde89244 (patch)
tree52464a169d9f608bdc4b9b1c0cc44c8383ea3e01 /source3
parent826ad16b363accc4029178cf9087b02362245e11 (diff)
downloadsamba-4c479f0574019afb2fc8a3dbfc802c75fde89244.tar.gz
samba-4c479f0574019afb2fc8a3dbfc802c75fde89244.tar.bz2
samba-4c479f0574019afb2fc8a3dbfc802c75fde89244.zip
split array-handling functions into separate module.
(This used to be commit cc2ce2b755b12cb3d97522aaee69b93309571abc)
Diffstat (limited to 'source3')
-rw-r--r--source3/Makefile.in1
-rw-r--r--source3/lib/util.c224
-rw-r--r--source3/lib/util_array.c248
3 files changed, 249 insertions, 224 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in
index cc254dd97f..a501da09b6 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -112,6 +112,7 @@ LIB_OBJ = lib/charcnv.o lib/charset.o lib/debug.o lib/fault.o \
lib/util_str.o lib/util_unistr.o \
lib/util_file.o mem_man/mem_man.o \
lib/util_sock.o lib/unix_sec_ctxt.o \
+ lib/util_array.o
UBIQX_OBJ = ubiqx/ubi_BinTree.o ubiqx/ubi_Cache.o ubiqx/ubi_SplayTree.o \
ubiqx/ubi_dLinkList.o ubiqx/ubi_sLinkList.o
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 54844fadcc..26f0482162 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -3228,227 +3228,3 @@ BOOL become_user_permanently(uid_t uid, gid_t gid)
return(True);
}
-void free_void_array(uint32 num_entries, void **entries,
- void(free_item)(void*))
-{
- uint32 i;
- if (entries != NULL)
- {
- for (i = 0; i < num_entries; i++)
- {
- if (entries[i] != NULL)
- {
- free_item(entries[i]);
- }
- }
- free(entries);
- }
-}
-
-void* add_item_to_array(uint32 *len, void ***array, const void *item,
- void*(item_dup)(const void*), BOOL alloc_anyway)
-{
- if (len == NULL || array == NULL || item_dup == NULL)
- {
- return NULL;
- }
-
- (*array) = (void**)Realloc((*array), ((*len)+1)*sizeof((*array)[0]));
-
- if ((*array) != NULL)
- {
- void* copy = NULL;
- if (item != NULL || alloc_anyway)
- {
- copy = item_dup(item);
- }
- (*array)[(*len)] = copy;
- (*len)++;
- return copy;
- }
- return NULL;
-}
-
-void free_char_array(uint32 num_entries, char **entries)
-{
- void(*fn)(void*) = (void(*)(void*))&free;
- free_void_array(num_entries, (void**)entries, *fn);
-}
-
-char* add_chars_to_array(uint32 *len, char ***array, const char *name)
-{
- void*(*fn)(const void*) = (void*(*)(const void*))&strdup;
- return (char*)add_item_to_array(len,
- (void***)array, (const void*)name, *fn, False);
-
-}
-
-void free_unistr_array(uint32 num_entries, UNISTR2 **entries)
-{
- void(*fn)(void*) = (void(*)(void*))&unistr2_free;
- free_void_array(num_entries, (void**)entries, *fn);
-}
-
-UNISTR2* add_unistr_to_array(uint32 *len, UNISTR2 ***array, UNISTR2 *name)
-{
- void*(*fn)(const void*) = (void*(*)(const void*))&unistr2_dup;
- return (UNISTR2*)add_item_to_array(len,
- (void***)array, (const void*)name, *fn, False);
-}
-
-void free_sid_array(uint32 num_entries, DOM_SID **entries)
-{
- void(*fn)(void*) = (void(*)(void*))&free;
- free_void_array(num_entries, (void**)entries, *fn);
-}
-
-DOM_SID* add_sid_to_array(uint32 *len, DOM_SID ***array, const DOM_SID *sid)
-{
- void*(*fn)(const void*) = (void*(*)(const void*))&sid_dup;
- return (DOM_SID*)add_item_to_array(len,
- (void***)array, (const void*)sid, *fn, False);
-}
-
-void free_devmode(DEVICEMODE *devmode)
-{
- if (devmode!=NULL)
- {
- if (devmode->private!=NULL)
- free(devmode->private);
- free(devmode);
- }
-}
-
-void free_printer_info_2(PRINTER_INFO_2 *printer)
-{
- if (printer!=NULL)
- {
- free_devmode(printer->devmode);
- free(printer);
- }
-}
-
-static PRINTER_INFO_2 *prt2_dup(const PRINTER_INFO_2* from)
-{
- PRINTER_INFO_2 *copy = (PRINTER_INFO_2 *)malloc(sizeof(PRINTER_INFO_2));
- if (copy != NULL)
- {
- if (from != NULL)
- {
- memcpy(copy, from, sizeof(*copy));
- }
- else
- {
- memset(copy, 0, sizeof(*copy));
- }
- }
- return copy;
-}
-
-void free_print2_array(uint32 num_entries, PRINTER_INFO_2 **entries)
-{
- void(*fn)(void*) = (void(*)(void*))&free_printer_info_2;
- free_void_array(num_entries, (void**)entries, *fn);
-}
-
-PRINTER_INFO_2 *add_print2_to_array(uint32 *len, PRINTER_INFO_2 ***array,
- const PRINTER_INFO_2 *prt)
-{
- void*(*fn)(const void*) = (void*(*)(const void*))&prt2_dup;
- return (PRINTER_INFO_2*)add_item_to_array(len,
- (void***)array, (const void*)prt, *fn, True);
-}
-
-static PRINTER_INFO_1 *prt1_dup(const PRINTER_INFO_1* from)
-{
- PRINTER_INFO_1 *copy = (PRINTER_INFO_1 *)malloc(sizeof(PRINTER_INFO_1));
- if (copy != NULL)
- {
- if (from != NULL)
- {
- memcpy(copy, from, sizeof(*copy));
- }
- else
- {
- memset(copy, 0, sizeof(*copy));
- }
- }
- return copy;
-}
-
-void free_print1_array(uint32 num_entries, PRINTER_INFO_1 **entries)
-{
- void(*fn)(void*) = (void(*)(void*))&free;
- free_void_array(num_entries, (void**)entries, *fn);
-}
-
-PRINTER_INFO_1 *add_print1_to_array(uint32 *len, PRINTER_INFO_1 ***array,
- const PRINTER_INFO_1 *prt)
-{
- void*(*fn)(const void*) = (void*(*)(const void*))&prt1_dup;
- return (PRINTER_INFO_1*)add_item_to_array(len,
- (void***)array, (const void*)prt, *fn, True);
-}
-
-static JOB_INFO_1 *job1_dup(const JOB_INFO_1* from)
-{
- JOB_INFO_1 *copy = (JOB_INFO_1 *)malloc(sizeof(JOB_INFO_1));
- if (copy != NULL)
- {
- if (from != NULL)
- {
- memcpy(copy, from, sizeof(*copy));
- }
- else
- {
- memset(copy, 0, sizeof(*copy));
- }
- }
- return copy;
-}
-
-void free_job1_array(uint32 num_entries, JOB_INFO_1 **entries)
-{
- void(*fn)(void*) = (void(*)(void*))&free;
- free_void_array(num_entries, (void**)entries, *fn);
-}
-
-JOB_INFO_1 *add_job1_to_array(uint32 *len, JOB_INFO_1 ***array,
- const JOB_INFO_1 *job)
-{
- void*(*fn)(const void*) = (void*(*)(const void*))&job1_dup;
- return (JOB_INFO_1*)add_item_to_array(len,
- (void***)array, (const void*)job, *fn, True);
-}
-
-static JOB_INFO_2 *job2_dup(const JOB_INFO_2* from)
-{
- JOB_INFO_2 *copy = (JOB_INFO_2 *)malloc(sizeof(JOB_INFO_2));
- if (copy != NULL)
- {
- if (from != NULL)
- {
- memcpy(copy, from, sizeof(*copy));
- }
- else
- {
- memset(copy, 0, sizeof(*copy));
- }
- }
- return copy;
-}
-
-void free_job2_array(uint32 num_entries, JOB_INFO_2 **entries)
-{
- void(*fn)(void*) = (void(*)(void*))&free;
- free_void_array(num_entries, (void**)entries, *fn);
-}
-
-JOB_INFO_2 *add_job2_to_array(uint32 *len, JOB_INFO_2 ***array,
- const JOB_INFO_2 *job)
-{
- void*(*fn)(const void*) = (void*(*)(const void*))&job2_dup;
- return (JOB_INFO_2*)add_item_to_array(len,
- (void***)array, (const void*)job, *fn, True);
-}
-
diff --git a/source3/lib/util_array.c b/source3/lib/util_array.c
new file mode 100644
index 0000000000..8df9079e7e
--- /dev/null
+++ b/source3/lib/util_array.c
@@ -0,0 +1,248 @@
+/*
+ Unix SMB/Netbios implementation.
+ Version 1.9.
+ Samba utility functions
+ Copyright (C) Andrew Tridgell 1992-1999
+ Copyright (C) Luke Kenneth Casson Leighton 1996-1999
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+
+void free_void_array(uint32 num_entries, void **entries,
+ void(free_item)(void*))
+{
+ uint32 i;
+ if (entries != NULL)
+ {
+ for (i = 0; i < num_entries; i++)
+ {
+ if (entries[i] != NULL)
+ {
+ free_item(entries[i]);
+ }
+ }
+ free(entries);
+ }
+}
+
+void* add_item_to_array(uint32 *len, void ***array, const void *item,
+ void*(item_dup)(const void*), BOOL alloc_anyway)
+{
+ if (len == NULL || array == NULL || item_dup == NULL)
+ {
+ return NULL;
+ }
+
+ (*array) = (void**)Realloc((*array), ((*len)+1)*sizeof((*array)[0]));
+
+ if ((*array) != NULL)
+ {
+ void* copy = NULL;
+ if (item != NULL || alloc_anyway)
+ {
+ copy = item_dup(item);
+ }
+ (*array)[(*len)] = copy;
+ (*len)++;
+ return copy;
+ }
+ return NULL;
+}
+
+void free_char_array(uint32 num_entries, char **entries)
+{
+ void(*fn)(void*) = (void(*)(void*))&free;
+ free_void_array(num_entries, (void**)entries, *fn);
+}
+
+char* add_chars_to_array(uint32 *len, char ***array, const char *name)
+{
+ void*(*fn)(const void*) = (void*(*)(const void*))&strdup;
+ return (char*)add_item_to_array(len,
+ (void***)array, (const void*)name, *fn, False);
+
+}
+
+void free_unistr_array(uint32 num_entries, UNISTR2 **entries)
+{
+ void(*fn)(void*) = (void(*)(void*))&unistr2_free;
+ free_void_array(num_entries, (void**)entries, *fn);
+}
+
+UNISTR2* add_unistr_to_array(uint32 *len, UNISTR2 ***array, UNISTR2 *name)
+{
+ void*(*fn)(const void*) = (void*(*)(const void*))&unistr2_dup;
+ return (UNISTR2*)add_item_to_array(len,
+ (void***)array, (const void*)name, *fn, False);
+}
+
+void free_sid_array(uint32 num_entries, DOM_SID **entries)
+{
+ void(*fn)(void*) = (void(*)(void*))&free;
+ free_void_array(num_entries, (void**)entries, *fn);
+}
+
+DOM_SID* add_sid_to_array(uint32 *len, DOM_SID ***array, const DOM_SID *sid)
+{
+ void*(*fn)(const void*) = (void*(*)(const void*))&sid_dup;
+ return (DOM_SID*)add_item_to_array(len,
+ (void***)array, (const void*)sid, *fn, False);
+}
+
+void free_devmode(DEVICEMODE *devmode)
+{
+ if (devmode!=NULL)
+ {
+ if (devmode->private!=NULL)
+ free(devmode->private);
+ free(devmode);
+ }
+}
+
+void free_printer_info_2(PRINTER_INFO_2 *printer)
+{
+ if (printer!=NULL)
+ {
+ free_devmode(printer->devmode);
+ free(printer);
+ }
+}
+
+static PRINTER_INFO_2 *prt2_dup(const PRINTER_INFO_2* from)
+{
+ PRINTER_INFO_2 *copy = (PRINTER_INFO_2 *)malloc(sizeof(PRINTER_INFO_2));
+ if (copy != NULL)
+ {
+ if (from != NULL)
+ {
+ memcpy(copy, from, sizeof(*copy));
+ }
+ else
+ {
+ memset(copy, 0, sizeof(*copy));
+ }
+ }
+ return copy;
+}
+
+void free_print2_array(uint32 num_entries, PRINTER_INFO_2 **entries)
+{
+ void(*fn)(void*) = (void(*)(void*))&free_printer_info_2;
+ free_void_array(num_entries, (void**)entries, *fn);
+}
+
+PRINTER_INFO_2 *add_print2_to_array(uint32 *len, PRINTER_INFO_2 ***array,
+ const PRINTER_INFO_2 *prt)
+{
+ void*(*fn)(const void*) = (void*(*)(const void*))&prt2_dup;
+ return (PRINTER_INFO_2*)add_item_to_array(len,
+ (void***)array, (const void*)prt, *fn, True);
+}
+
+static PRINTER_INFO_1 *prt1_dup(const PRINTER_INFO_1* from)
+{
+ PRINTER_INFO_1 *copy = (PRINTER_INFO_1 *)malloc(sizeof(PRINTER_INFO_1));
+ if (copy != NULL)
+ {
+ if (from != NULL)
+ {
+ memcpy(copy, from, sizeof(*copy));
+ }
+ else
+ {
+ memset(copy, 0, sizeof(*copy));
+ }
+ }
+ return copy;
+}
+
+void free_print1_array(uint32 num_entries, PRINTER_INFO_1 **entries)
+{
+ void(*fn)(void*) = (void(*)(void*))&free;
+ free_void_array(num_entries, (void**)entries, *fn);
+}
+
+PRINTER_INFO_1 *add_print1_to_array(uint32 *len, PRINTER_INFO_1 ***array,
+ const PRINTER_INFO_1 *prt)
+{
+ void*(*fn)(const void*) = (void*(*)(const void*))&prt1_dup;
+ return (PRINTER_INFO_1*)add_item_to_array(len,
+ (void***)array, (const void*)prt, *fn, True);
+}
+
+static JOB_INFO_1 *job1_dup(const JOB_INFO_1* from)
+{
+ JOB_INFO_1 *copy = (JOB_INFO_1 *)malloc(sizeof(JOB_INFO_1));
+ if (copy != NULL)
+ {
+ if (from != NULL)
+ {
+ memcpy(copy, from, sizeof(*copy));
+ }
+ else
+ {
+ memset(copy, 0, sizeof(*copy));
+ }
+ }
+ return copy;
+}
+
+void free_job1_array(uint32 num_entries, JOB_INFO_1 **entries)
+{
+ void(*fn)(void*) = (void(*)(void*))&free;
+ free_void_array(num_entries, (void**)entries, *fn);
+}
+
+JOB_INFO_1 *add_job1_to_array(uint32 *len, JOB_INFO_1 ***array,
+ const JOB_INFO_1 *job)
+{
+ void*(*fn)(const void*) = (void*(*)(const void*))&job1_dup;
+ return (JOB_INFO_1*)add_item_to_array(len,
+ (void***)array, (const void*)job, *fn, True);
+}
+
+static JOB_INFO_2 *job2_dup(const JOB_INFO_2* from)
+{
+ JOB_INFO_2 *copy = (JOB_INFO_2 *)malloc(sizeof(JOB_INFO_2));
+ if (copy != NULL)
+ {
+ if (from != NULL)
+ {
+ memcpy(copy, from, sizeof(*copy));
+ }
+ else
+ {
+ memset(copy, 0, sizeof(*copy));
+ }
+ }
+ return copy;
+}
+
+void free_job2_array(uint32 num_entries, JOB_INFO_2 **entries)
+{
+ void(*fn)(void*) = (void(*)(void*))&free;
+ free_void_array(num_entries, (void**)entries, *fn);
+}
+
+JOB_INFO_2 *add_job2_to_array(uint32 *len, JOB_INFO_2 ***array,
+ const JOB_INFO_2 *job)
+{
+ void*(*fn)(const void*) = (void*(*)(const void*))&job2_dup;
+ return (JOB_INFO_2*)add_item_to_array(len,
+ (void***)array, (const void*)job, *fn, True);
+}
+