Fixes to improve portability (especially to OS X, Solaris, OpenBSD).
[ircu2.10.12-pk.git] / ircd / memdebug.c
index 15db3795b4002589f89db6d8ea1b2ea0d44d076a..4650e1df7c687562b11accd8f8a12f8220d8c2be 100644 (file)
@@ -28,7 +28,7 @@ extern int GC_find_leak;
 
 struct MemHeader
 {
-  u_int32_t magic;
+  uint32_t magic;
   char type[32];
   char file[32];
   int line;
@@ -47,7 +47,7 @@ memfrob(void *p, size_t len)
   for (s = (char*)p, se = s + (len & ~3) - 4;
        s <= se;
        s += 4)
-    *(u_int32_t*)s = *(u_int32_t*)pat;
+    *(uint32_t*)s = *(uint32_t*)pat;
   for (se = s; se < s; s++)
     *s = pat[i++];
 }
@@ -103,6 +103,27 @@ dbg_malloc_zero(size_t size, const char *type, const char *file, int line)
   return (void*)(mh + 1);
 }
 
+void*
+dbg_realloc(void *ptr, size_t size, const char *file, int line)
+{
+  struct MemHeader *mh, *mh2;
+  if (ptr == NULL)
+    return dbg_malloc(size, "realloc", file, line);
+  mh = (struct MemHeader*)ptr - 1;
+  assert(mh->magic == 0xA110CA7E);
+  if (mh->length >= size)
+    return mh;
+  mh2 = dbg_malloc(size, "realloc", file, line);
+  if (mh2 == NULL)
+  {
+    dbg_free(mh+1, file, line);
+    return NULL;
+  }
+  memcpy(mh2+1, mh+1, mh->length);
+  dbg_free(mh+1, file, line);
+  return (void*)(mh2+1);
+}
+
 void
 dbg_free(void *ptr, const char *file, int line)
 {