MCPcopy Create free account
hub / github.com/OpenPrinting/cups / cupsArrayDup

Function cupsArrayDup

cups/array.c:351–427  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

349 */
350
351cups_array_t * /* O - Duplicate array */
352cupsArrayDup(cups_array_t *a) /* I - Array */
353{
354 cups_array_t *da; /* Duplicate array */
355
356
357 /*
358 * Range check input...
359 */
360
361 if (!a)
362 return (NULL);
363
364 /*
365 * Allocate memory for the array...
366 */
367
368 da = calloc(1, sizeof(cups_array_t));
369 if (!da)
370 return (NULL);
371
372 da->compare = a->compare;
373 da->data = a->data;
374 da->current = a->current;
375 da->insert = a->insert;
376 da->unique = a->unique;
377 da->num_saved = a->num_saved;
378
379 memcpy(da->saved, a->saved, sizeof(a->saved));
380
381 if (a->num_elements)
382 {
383 /*
384 * Allocate memory for the elements...
385 */
386
387 da->elements = malloc((size_t)a->num_elements * sizeof(void *));
388 if (!da->elements)
389 {
390 free(da);
391 return (NULL);
392 }
393
394 /*
395 * Copy the element pointers...
396 */
397
398 if (a->copyfunc)
399 {
400 /*
401 * Use the copy function to make a copy of each element...
402 */
403
404 int i; /* Looping var */
405
406 for (i = 0; i < a->num_elements; i ++)
407 da->elements[i] = (a->copyfunc)(a->elements[i], a->data);
408 }

Callers 2

cupsdCopyLocationFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by 1

mainFunction · 0.68