diff options
| author | Craig Barnes <craigbarnes@protonmail.com> | 2020-08-07 00:05:04 +0000 |
|---|---|---|
| committer | Craig Barnes <craigbarnes@protonmail.com> | 2020-08-07 00:05:04 +0000 |
| commit | 4564c8251353af6caf9c1bb8125377f4579dc596 (patch) | |
| tree | bbd32fb881bf19fb60a13d29d9904b6fbf070f6e /xmalloc.c | |
| parent | Merge branch 'desktop-keywords' into master (diff) | |
xmalloc: add xrealloc() and xstrndup() functions
Diffstat (limited to 'xmalloc.c')
| -rw-r--r-- | xmalloc.c | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -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) { |
