Skip to content

Commit

Permalink
Add xrecallocarray.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicm committed Nov 28, 2019
1 parent 9ea05b2 commit c416fe0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions xmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ xreallocarray(void *ptr, size_t nmemb, size_t size)
return new_ptr;
}

void *
xrecallocarray(void *ptr, size_t oldnmemb, size_t nmemb, size_t size)
{
void *new_ptr;

if (nmemb == 0 || size == 0)
fatalx("xrecallocarray: zero size");
new_ptr = recallocarray(ptr, oldnmemb, nmemb, size);
if (new_ptr == NULL)
fatalx("xrecallocarray: allocating %zu * %zu bytes: %s",
nmemb, size, strerror(errno));
return new_ptr;
}

char *
xstrdup(const char *str)
{
Expand Down
1 change: 1 addition & 0 deletions xmalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void *xmalloc(size_t);
void *xcalloc(size_t, size_t);
void *xrealloc(void *, size_t);
void *xreallocarray(void *, size_t, size_t);
void *xrecallocarray(void *, size_t, size_t, size_t);
char *xstrdup(const char *);
char *xstrndup(const char *, size_t);
int xasprintf(char **, const char *, ...)
Expand Down

0 comments on commit c416fe0

Please sign in to comment.