diff options
Diffstat (limited to 'mem-pool.c')
-rw-r--r-- | mem-pool.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/mem-pool.c b/mem-pool.c index a2841a4a9a..020b51e0c5 100644 --- a/mem-pool.c +++ b/mem-pool.c @@ -102,6 +102,24 @@ void *mem_pool_calloc(struct mem_pool *mem_pool, size_t count, size_t size) return r; } +char *mem_pool_strdup(struct mem_pool *pool, const char *str) +{ + size_t len = strlen(str) + 1; + char *ret = mem_pool_alloc(pool, len); + + return memcpy(ret, str, len); +} + +char *mem_pool_strndup(struct mem_pool *pool, const char *str, size_t len) +{ + char *p = memchr(str, '\0', len); + size_t actual_len = (p ? p - str : len); + char *ret = mem_pool_alloc(pool, actual_len+1); + + ret[actual_len] = '\0'; + return memcpy(ret, str, actual_len); +} + int mem_pool_contains(struct mem_pool *mem_pool, void *mem) { struct mp_block *p; |