diff options
Diffstat (limited to 'support/xalloc.h')
-rw-r--r-- | support/xalloc.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/support/xalloc.h b/support/xalloc.h index bb893294..38a14873 100644 --- a/support/xalloc.h +++ b/support/xalloc.h @@ -436,5 +436,16 @@ xpalloc (void *pa, idx_t *nitems, idx_t nitems_incr_min, return pa; } +/* Clone an object P of size S, with error checking. Append + a terminating NUL byte. */ + +char * +ximemdup0 (void const *p, idx_t s) +{ + char *result = malloc(s + 1); + result[s] = 0; + return memcpy (result, p, s); +} + #endif /* !XALLOC_H_ */ |