diff options
Diffstat (limited to 'src/shared/util.c')
-rw-r--r-- | src/shared/util.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c index 873c95820a..760013c1fb 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -5855,3 +5855,20 @@ char *strrep(const char *s, unsigned n) { *p = 0; return r; } + +void* greedy_realloc(void **p, size_t *allocated, size_t need) { + size_t a; + void *q; + + if (*allocated >= need) + return *p; + + a = MAX(64, need * 2); + q = realloc(*p, a); + if (!q) + return NULL; + + *p = q; + *allocated = a; + return q; +} |