ref: d7b955f42d01be3dfa590b476287879bf0e046d1
parent: 439fd8a6d2e636acabe21de2b9223d1030adc8b0
author: Roberto E. Vargas Caballero <[email protected]>
date: Wed Aug 15 16:34:17 EDT 2012
Added xrealloc function This new function is a wrapper over standard realloc, and always return a valid pointer. In case of error call to the function out_of_memory, which will handle the situation.
--- a/cc.h
+++ b/cc.h
@@ -24,4 +24,5 @@
extern void *xmalloc(size_t size);
extern void *xcalloc(size_t nmemb, size_t size);
extern char *xstrdup(const char *s);
+extern void *xrealloc(void *buff, register size_t size);
#endif
--- a/wrapper.c
+++ b/wrapper.c
@@ -39,3 +39,13 @@
return memcpy(p, s, len);
}
+
+void *
+xrealloc(void *buff, register size_t size)
+{
+ register void *p = realloc(buff, size);
+
+ if (!p)
+ out_of_memory();
+ return p;
+}