diff options
author | Patrick Williams <iawillia@us.ibm.com> | 2011-05-20 15:39:34 -0500 |
---|---|---|
committer | A. Patrick Williams III <iawillia@us.ibm.com> | 2011-05-20 15:51:37 -0500 |
commit | 5240aadc816acdd255e1c6d65fefbcca079d8ad3 (patch) | |
tree | dbe1fe492c43ece902a3e8372e3fbf052068ef2e /src/lib | |
parent | 8828d95005c95ce736100521a246f40d22febbcc (diff) | |
download | blackbird-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.C | 28 |
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; +} |