]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/mini-os.git/commitdiff
minios: add realloc
authorKeir Fraser <keir.fraser@citrix.com>
Thu, 17 Jan 2008 15:06:30 +0000 (15:06 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Thu, 17 Jan 2008 15:06:30 +0000 (15:06 +0000)
Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
Signed-off-by: Tim Deegan <tim.deegan@eu.citrix.com>
include/xmalloc.h
lib/xmalloc.c

index f5e721fa1603c2fc9a4a4d3b7c48a78f8e239888..e8052ac68d31f5002c1b426b588aa9567f9c1a75 100644 (file)
@@ -9,12 +9,15 @@
 
 #define malloc(size) _xmalloc(size, 4)
 #define free(ptr) xfree(ptr)
+#define realloc(ptr, size) _realloc(ptr, size)
 
 /* Free any of the above. */
 extern void xfree(const void *);
 
 /* Underlying functions */
 extern void *_xmalloc(size_t size, size_t align);
+extern void *_realloc(void *ptr, size_t size);
+
 static inline void *_xmalloc_array(size_t size, size_t align, size_t num)
 {
        /* Check for overflow. */
index 3246d57b32914ca04918a7dd0f95359602e3b9eb..de0001b31dce9b7965611f16a0230f822c14215b 100644 (file)
@@ -223,3 +223,24 @@ void xfree(const void *p)
     /* spin_unlock_irqrestore(&freelist_lock, flags); */
 }
 
+void *_realloc(void *ptr, size_t size)
+{
+    void *new;
+    struct xmalloc_hdr *hdr;
+
+    if (ptr == NULL)
+        return _xmalloc(size, 4);
+
+    hdr = (struct xmalloc_hdr *)ptr - 1;
+    if (hdr->size >= size) 
+        return ptr;
+    
+    new = _xmalloc(size, 4);
+    if (new == NULL) 
+        return NULL;
+
+    memcpy(new, ptr, hdr->size);
+    xfree(ptr);
+
+    return new;
+}