commit d7b955f42d01be3dfa590b476287879bf0e046d1
parent 439fd8a6d2e636acabe21de2b9223d1030adc8b0
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Wed, 15 Aug 2012 20:34:17 +0200
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.
Diffstat:
2 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/cc.h b/cc.h
@@ -24,4 +24,5 @@ extern void warning_error(char flag, const char *fmt, ...);
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
diff --git a/wrapper.c b/wrapper.c
@@ -39,3 +39,13 @@ xstrdup(const char *s)
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;
+}