]> granicus.if.org Git - check/commitdiff
* define rpl_malloc and rpl_realloc for platforms where
authorcpickett <cpickett@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Tue, 19 Jun 2007 23:36:39 +0000 (23:36 +0000)
committercpickett <cpickett@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Tue, 19 Jun 2007 23:36:39 +0000 (23:36 +0000)
  !malloc(0) and !realloc(0,0), such as AIX, because configure
  goes and redefines malloc/realloc in this case...

git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@411 64e312b2-a51f-0410-8e61-82d0ca0eb02a

src/check.c

index c6830ade26eef0932731d15765a8338b95f16f44..57b23485c4c93681d99ae52dabf66f5c15f349e4 100644 (file)
@@ -47,6 +47,38 @@ static void tr_init (TestResult *tr);
 static void suite_free (Suite *s);
 static void tcase_free (TCase *tc);
 
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+#undef malloc
+#undef realloc
+
+#include <sys/types.h>
+
+void *malloc ();
+void *realloc ();
+
+/* Allocate an N-byte block of memory from the heap. If N is zero,
+   allocate a 1-byte block. */
+void *
+rpl_malloc (size_t n)
+{
+  if (n == 0)
+    n = 1;
+  return malloc (n);
+} 
+
+/* configure defines realloc to rpl_realloc if realloc(0,0) is NULL */
+void *
+rpl_realloc (void *p, size_t n)
+{
+  if (n == 0)
+    n = 1;
+  if (p == 0)
+    return malloc (n);
+  return realloc (p, n);
+}
+
 Suite *suite_create (const char *name)
 {
   Suite *s;