basic/alloc-util: add greedy_realloc_append()
Add function to perform greedy realloc as well as copying the new data into the newly allocated space.
This commit is contained in:
@@ -103,6 +103,33 @@ void* greedy_realloc0(
|
||||
return q;
|
||||
}
|
||||
|
||||
void* greedy_realloc_append(
|
||||
void **p,
|
||||
size_t *n_p,
|
||||
const void *from,
|
||||
size_t n_from,
|
||||
size_t size) {
|
||||
|
||||
uint8_t *q;
|
||||
|
||||
assert(p);
|
||||
assert(n_p);
|
||||
assert(from || n_from == 0);
|
||||
|
||||
if (n_from > SIZE_MAX - *n_p)
|
||||
return NULL;
|
||||
|
||||
q = greedy_realloc(p, *n_p + n_from, size);
|
||||
if (!q)
|
||||
return NULL;
|
||||
|
||||
memcpy_safe(q + *n_p * size, from, n_from * size);
|
||||
|
||||
*n_p += n_from;
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
void *expand_to_usable(void *ptr, size_t newsize _unused_) {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user