Implementation of `pvPortRealloc`.

pull/3/head
David Garske 2018-07-02 16:15:30 -07:00
parent febeae793e
commit 930668abf2
2 changed files with 54 additions and 0 deletions

View File

@ -308,6 +308,33 @@ BlockLink_t *pxLink;
}
/*-----------------------------------------------------------*/
void *pvPortRealloc( void *pv, size_t xWantedSize )
{
void *pvReturn = NULL;
if(pv)
{
BlockLink_t *pxLink = (BlockLink_t *)((char*)pv - xHeapStructSize);
if(pxLink->xBlockSize & xBlockAllocatedBit)
{
uint32_t blockSize = (pxLink->xBlockSize & ~xBlockAllocatedBit);
blockSize -= (xHeapStructSize + HEAP_CHECK_SIZE);
pvReturn = pvPortMalloc(xWantedSize);
if(pvReturn)
{
memcpy(pvReturn, pv, blockSize);
vPortFree(pv);
}
}
}
else {
pvReturn = pvPortMalloc(xWantedSize);
}
return pvReturn;
}
/*-----------------------------------------------------------*/
size_t xPortGetFreeHeapSize( void )
{
return xFreeBytesRemaining;

View File

@ -317,6 +317,33 @@ BlockLink_t *pxLink;
}
/*-----------------------------------------------------------*/
void *pvPortRealloc( void *pv, size_t xWantedSize )
{
void *pvReturn = NULL;
if(pv)
{
BlockLink_t *pxLink = (BlockLink_t *)((char*)pv - uxHeapStructSize);
if(pxLink->xBlockSize & xBlockAllocatedBit)
{
uint32_t blockSize = (pxLink->xBlockSize & ~xBlockAllocatedBit);
blockSize -= (uxHeapStructSize + HEAP_CHECK_SIZE);
pvReturn = pvPortMalloc(xWantedSize);
if(pvReturn)
{
memcpy(pvReturn, pv, blockSize);
vPortFree(pv);
}
}
}
else {
pvReturn = pvPortMalloc(xWantedSize);
}
return pvReturn;
}
/*-----------------------------------------------------------*/
size_t xPortGetFreeHeapSize( void )
{
return xFreeBytesRemaining;