Appends the chain with the first nBytes nB (void*) buffer of given size. This operation makes no assumptions about buffer content and so the operation is not null terminated.
| Return Type | Function name | Arguments |
|---|---|---|
| uint32_t | hzChain::Append | (const void*,uint32_t,) |
Declared in file: hzChain.h
Defined in file : hzChain.cpp
Function Logic:
Function body:
uint32_t hzChain::Append (const void* vpStr)uint32_t nBytes,
{
// Appends the chain with the first nBytes nB (void*) buffer of given size. This operation makes no assumptions about buffer content and so the operation is
// not null terminated.
//
// Arguments: 1) vpStr The buffer address as void*
// 2) nBytes The number of bytes from the buffer to append to the chain
//
// Returns: Number of bytes added
_hzfunc("hzChain::Append(1)") ;
_zblk* curBlk ; // Working block pointer
_zblk* newBlk ; // Working block pointer
const char* i ; // Input iterator
uint32_t nCan ; // Max number of bytes that can be written to current block
uint32_t nWritten = 0; // Limiter
if (!nBytes)
return nBytes ;
// If nothing in chain, create the first block
if (!mx)
{ mx = new _chain() ; mx->m_Test = mx ; }
if (!mx->m_Begin)
mx->m_Begin = mx->m_End = _zblk_alloc() ;
curBlk = (_zblk*) mx->m_End ;
if (!curBlk)
hzexit(E_MEMORY, "Chain %p has no end block\n", this) ;
i = (char*) vpStr ;
for (; nWritten < nBytes ;)
{
if (curBlk->m_nUsage == ZBLKSIZE)
{
// Out of space - make new block
newBlk = _zblk_alloc() ;
newBlk->Prev(curBlk) ;
curBlk->Next(newBlk) ;
mx->m_End = curBlk = newBlk ;
}
nCan = ZBLKSIZE - curBlk->m_nUsage ;
if ((nWritten + nCan) > nBytes)
nCan = nBytes - nWritten ;
// Add bytes to current block
// threadLog("Appending %u bytes to posn %u\n", nCan, curBlk->m_nUsage) ;
memcpy(curBlk->m_Data + curBlk->m_nUsage, i, nCan) ;
curBlk->m_nUsage += nCan ;
i += nCan ;
mx->m_nSize += nCan ;
nWritten += nCan ;
}
return nWritten ;
}