xmalloc: add xrealloc() and xstrndup() functions

This commit is contained in:
Craig Barnes 2020-08-07 01:05:04 +01:00
parent 22eed3e579
commit 4564c82513
2 changed files with 15 additions and 0 deletions

View file

@ -42,12 +42,25 @@ xcalloc(size_t nmemb, size_t size)
return check_alloc(calloc(nmemb, size));
}
void *
xrealloc(void *ptr, size_t size)
{
void *alloc = realloc(ptr, size);
return unlikely(size == 0) ? alloc : check_alloc(alloc);
}
char *
xstrdup(const char *str)
{
return check_alloc(strdup(str));
}
char *
xstrndup(const char *str, size_t n)
{
return check_alloc(strndup(str, n));
}
static VPRINTF(2) int
xvasprintf_(char **strp, const char *format, va_list ap)
{