This source file includes following definitions.
- __libc_dynarray_resize
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #ifndef _LIBC
20 # include <libc-config.h>
21 #endif
22
23 #include <dynarray.h>
24 #include <errno.h>
25 #include <intprops.h>
26 #include <stdlib.h>
27 #include <string.h>
28
29 bool
30 __libc_dynarray_resize (struct dynarray_header *list, size_t size,
31 void *scratch, size_t element_size)
32 {
33
34 if (size <= list->allocated)
35 {
36 list->used = size;
37 return true;
38 }
39
40
41
42
43
44 size_t new_size_bytes;
45 if (INT_MULTIPLY_WRAPV (size, element_size, &new_size_bytes))
46 {
47
48 __set_errno (ENOMEM);
49 return false;
50 }
51 void *new_array;
52 if (list->array == scratch)
53 {
54
55 new_array = malloc (new_size_bytes);
56 if (new_array != NULL && list->array != NULL)
57 memcpy (new_array, list->array, list->used * element_size);
58 }
59 else
60 new_array = realloc (list->array, new_size_bytes);
61 if (new_array == NULL)
62 return false;
63 list->array = new_array;
64 list->allocated = size;
65 list->used = size;
66 return true;
67 }
68 libc_hidden_def (__libc_dynarray_resize)