Commit 2f13c1c9 authored by Ivan Donchevskiy's avatar Ivan Donchevskiy

Added function to check heading match in file in TableBlockStorage

parent accf2dca
......@@ -126,6 +126,8 @@ class TableBlockStorage
inline int getByteSize() { return (size*full_size + sizeof(StorageAttr)); }
bool checkAttr( int key_sz, int inf_sz, int sz, int block_num, int block_lim, int seek );
protected:
FILE *file;
int inf_size;
......
......@@ -115,6 +115,29 @@ bool TableBlockStorage::copyToNextBlock(void)
return true;
}
/*! */
bool TableBlockStorage::checkAttr( int key_sz, int inf_sz, int inf_count, int block_num, int block_lim, int seek )
{
if( file==NULL ) return false;
int tmpsize=inf_count*block_num;
fseek(file, seek, 0);
/*! */
StorageAttr sa;
fread(&sa,sizeof(StorageAttr),1,file);
/*! */
if((sa.k_size!=key_sz)||(sa.inf_size!=inf_sz)||(sa.size!=tmpsize)||(sa.block_number!=block_num)||(sa.lim!=block_lim)||(sa.seekpos!=seek))
{
fclose(file);
file=NULL;
return false;
}
return true;
}
bool TableBlockStorage::open(const char* name, int byte_sz, int key_sz, int inf_sz, int inf_count, int block_num, int block_lim, int seek)
{
/*! , */
......@@ -131,21 +154,10 @@ bool TableBlockStorage::open(const char* name, int byte_sz, int key_sz, int inf_
return false;
}
/*! */
StorageAttr sa;
fread(&sa,sizeof(StorageAttr),1,file);
full_size = sizeof(TableBlockStorageElem)+key_sz+inf_sz;
int tmpsize=inf_count*block_num;
/*! */
if((sa.k_size!=key_sz)||(sa.inf_size!=inf_sz)||(sa.size!=tmpsize)||(sa.block_number!=block_num)||(sa.lim!=block_lim)||(sa.seekpos!=seek))
{
fclose(file);
file=NULL;
if( !checkAttr(key_sz, inf_sz, inf_count, block_num, block_lim, seek ) )
return false;
}
k_size=key_sz;
inf_size=inf_sz;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment