예제 #1
0
static char *AddToStringTable( stringtable *strtab, void *data, unsigned len, bool addnullchar )
/**********************************************************************************************/
{
    stringblock *blk;
    unsigned    diff;
    char *      dest;

    if( addnullchar )
        ++len;
    if( strtab->currbase & 1 && len > STR_BLOCK_SIZE ) {
        LnkMsg( ERR+MSG_SYMBOL_NAME_TOO_LONG, "s", data );
        len = STR_BLOCK_SIZE;
    }
    for( blk = RingLast( strtab->data ); blk->size + len > STR_BLOCK_SIZE; blk = AllocNewBlock( strtab ) ) {
        diff = STR_BLOCK_SIZE - blk->size;
        if( diff != 0 ) {
            if( strtab->currbase & 1 ) {        // then don't split
                memset( &blk->data[blk->size], 0, diff );
            } else {
                memcpy( &blk->data[blk->size], data, diff );
                len -= diff;
                data = (char *)data + diff;
            }
        }
        blk->size = STR_BLOCK_SIZE;
        strtab->currbase += STR_BLOCK_SIZE;
    }
    dest = &blk->data[blk->size];
    blk->size += len;
    if( addnullchar )
        dest[ --len ] = '\0';
    memcpy( dest, data, len );
    return( dest );
}
예제 #2
0
offset_type BlockManager::AllocBlock()
{
    FileAutoLock lock(m_pLock);
    if(m_Header.Unused.offset < 0)
        return AllocNewBlock();
    else
        return AllocExistBlock();
}
예제 #3
0
void InitStringTable( stringtable *strtab, bool dontsplit )
/****************************************************************/
{
    strtab->data = NULL;
    if( dontsplit ) {
        strtab->currbase = 1;
    } else {
        strtab->currbase = 0;
    }
    AllocNewBlock( strtab );
}
예제 #4
0
void ReserveStringTable( stringtable *strtab, unsigned len )
/*****************************************************************/
{
    stringblock *blk;
    unsigned    diff;

    blk = RingLast( strtab->data );
    if( blk->size + len > STR_BLOCK_SIZE && strtab->currbase & 1 ) {
        diff = STR_BLOCK_SIZE - blk->size;
        if( diff != 0 ) {
            memset( &blk->data[blk->size], 0, diff );
        }
        blk->size = STR_BLOCK_SIZE;
        strtab->currbase += STR_BLOCK_SIZE;
        blk = AllocNewBlock( strtab );
    }
}