mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-04 04:06:06 -05:00
xmalloc: add xrealloc() and xstrndup() functions
This commit is contained in:
parent
22eed3e579
commit
4564c82513
2 changed files with 15 additions and 0 deletions
13
xmalloc.c
13
xmalloc.c
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue