]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/alloc-util.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
6 #include "alloc-util.h"
10 void* memdup(const void *p
, size_t l
) {
23 void* memdup_suffix0(const void *p
, size_t l
) {
28 /* The same as memdup() but place a safety NUL byte after the allocated memory */
34 *((uint8_t*) mempcpy(ret
, p
, l
)) = 0;
38 void* greedy_realloc(void **p
, size_t *allocated
, size_t need
, size_t size
) {
45 if (*allocated
>= need
)
48 newalloc
= MAX(need
* 2, 64u / size
);
51 /* check for overflows */
60 *allocated
= newalloc
;
64 void* greedy_realloc0(void **p
, size_t *allocated
, size_t need
, size_t size
) {
73 q
= greedy_realloc(p
, allocated
, need
, size
);
77 if (*allocated
> prev
)
78 memzero(q
+ prev
* size
, (*allocated
- prev
) * size
);