summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorPatrick Williams <iawillia@us.ibm.com>2011-05-20 15:39:34 -0500
committerA. Patrick Williams III <iawillia@us.ibm.com>2011-05-20 15:51:37 -0500
commit5240aadc816acdd255e1c6d65fefbcca079d8ad3 (patch)
treedbe1fe492c43ece902a3e8372e3fbf052068ef2e /src/lib
parent8828d95005c95ce736100521a246f40d22febbcc (diff)
downloadblackbird-hostboot-5240aadc816acdd255e1c6d65fefbcca079d8ad3.tar.gz
blackbird-hostboot-5240aadc816acdd255e1c6d65fefbcca079d8ad3.zip
Simple realloc implementation.
Change-Id: I76c162bbb3efb97d91d498d4571c1d81d15e5663 Reviewed-on: http://gfwr801.rchland.ibm.com:8080/gerrit/93 Tested-by: Jenkins Server Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com>
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/stdlib.C28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/lib/stdlib.C b/src/lib/stdlib.C
index 5bf0d87f6..8aa6b36eb 100644
--- a/src/lib/stdlib.C
+++ b/src/lib/stdlib.C
@@ -1,4 +1,5 @@
#include <stdlib.h>
+#include <string.h>
#include <kernel/heapmgr.H>
#include <kernel/pagemgr.H>
@@ -33,3 +34,30 @@ void free(void* p)
HeapManager::free(p);
}
}
+
+void* realloc(void* p, size_t s)
+{
+ if (NULL == p) return malloc(s);
+
+ size_t* len = (size_t*)p;
+ len--;
+
+ size_t cur_size;
+ if ((*len) > 0xff)
+ {
+ cur_size = ((*len) >> 8) * PageManager::PAGESIZE - 8;
+ }
+ else
+ {
+ cur_size = (1 << (*len + 4)) - 8;
+ }
+
+ if (s < cur_size)
+ return p;
+
+ void* new_p = malloc(s);
+ memcpy(new_p, p, cur_size);
+ free(p);
+
+ return new_p;
+}
OpenPOWER on IntegriCloud