diff options
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/util.c | 85 |
1 files changed, 83 insertions, 2 deletions
diff --git a/source3/lib/util.c b/source3/lib/util.c index 4e18cb93ba..54844fadcc 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -2933,7 +2933,7 @@ void out_ascii(FILE *f, const unsigned char *buf,int len) void out_struct(FILE *f, const char *buf1,int len, int per_line) { - const unsigned char *buf = (unsigned char *)buf1; + const unsigned char *buf = (const unsigned char *)buf1; int i; if (len<=0) @@ -3309,6 +3309,25 @@ DOM_SID* add_sid_to_array(uint32 *len, DOM_SID ***array, const DOM_SID *sid) (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)); @@ -3328,7 +3347,7 @@ static PRINTER_INFO_2 *prt2_dup(const PRINTER_INFO_2* from) void free_print2_array(uint32 num_entries, PRINTER_INFO_2 **entries) { - void(*fn)(void*) = (void(*)(void*))&free; + void(*fn)(void*) = (void(*)(void*))&free_printer_info_2; free_void_array(num_entries, (void**)entries, *fn); } @@ -3371,3 +3390,65 @@ PRINTER_INFO_1 *add_print1_to_array(uint32 *len, PRINTER_INFO_1 ***array, (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); +} + |