library/src/blockclass/BP-BlockClass.cc
//! retrieves file contents of a given file.
retrieves file contents of a given file.
retrieves file contents of a given file .
int Block::FileGetContents(char *file)
{
	if(!file)
		return ERR_FAILURE;
	if(!BP_FileAtPathExistsAndIsReadable(file))
	{
		this->AddErrorToStack((char *) "Error. Tried to open file as readable.  Open failed.  Check file exists and is readable");
		return ERR_FAILURE;
	}
	if(this->File_Open(file, (char *) "r") != ERR_SUCCESS)
	{
		this->AddWarningToStack((char *) "Error.  Cannot open file.");
		return ERR_FAILURE;
	}
	char read_byte = (char) 0x00;
	this->got_contents = NULL;
	this->got_contents_size = 0;
	while(this->File_Read(&read_byte, 1))
	{
		this->got_contents_size++;
		this->got_contents      = (char *) tq_realloc(this->tq, this->got_contents, this->got_contents_size+1, BPLN);
		this->got_contents[this->got_contents_size-1] = read_byte;
		this->got_contents[this->got_contents_size] = 0x00;
	}
	this->File_Close();
	return ERR_SUCCESS;
}
int Block :: FileGetContents ( char * file ) { if ( ! file ) return ERR_FAILURE ; if ( ! BP_FileAtPathExistsAndIsReadable ( file ) ) { this -> AddErrorToStack ( ( char * ) " " ) ; return ERR_FAILURE ; } if ( this -> File_Open ( file , ( char * ) " " ) != ERR_SUCCESS ) { this -> AddWarningToStack ( ( char * ) " " ) ; return ERR_FAILURE ; } char read_byte = ( char ) 0x00 ; this -> got_contents = NULL ; this -> got_contents_size = 0 ; while ( this -> File_Read ( & read_byte , 1 ) ) { this -> got_contents_size ++ ; this -> got_contents = ( char * ) tq_realloc ( this -> tq , this -> got_contents , this -> got_contents_size + 1 , BPLN ) ; this -> got_contents [ this -> got_contents_size - 1 ] = read_byte ; this -> got_contents [ this -> got_contents_size ] = 0x00 ; } this -> File_Close ( ) ; return ERR_SUCCESS ; }
retrieves file contents of a given file.
retrieves file contents of a given file .
// ensure we have a file // check to see if the file exists and is readable // open file // create space for writer byte // read the file byte by byte and allocate/assign (lazy) // increment got contents size // realloc the buffer // copy in read byte // terminate // close the file // return indicating success