예제 #1
0
파일: tinyxml.cpp 프로젝트: chewi/Aquaria
bool TiXmlDocument::LoadFile( VFILE* file, TiXmlEncoding encoding )
{
	if ( !file ) 
	{
		SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN );
		return false;
	}

	// Delete the existing data:
	Clear();
	location.Clear();

	// Get the file size, so we can pre-allocate the string. HUGE speed impact.
	size_t length = 0;

	// Strange case, but good to handle up front.
	if ( vfsize(file, &length) < 0 || length <= 0 )
	{
		SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
		return false;
	}

	// Subtle bug here. TinyXml did use fgets. But from the XML spec:
	// 2.11 End-of-Line Handling
	// <snip>
	// <quote>
	// ...the XML processor MUST behave as if it normalized all line breaks in external 
	// parsed entities (including the document entity) on input, before parsing, by translating 
	// both the two-character sequence #xD #xA and any #xD that is not followed by #xA to 
	// a single #xA character.
	// </quote>
	//
	// It is not clear fgets does that, and certainly isn't clear it works cross platform. 
	// Generally, you expect fgets to translate from the convention of the OS to the c/unix
	// convention, and not work generally.

	/*
	while( fgets( buf, sizeof(buf), file ) )
	{
		data += buf;
	}
	*/

	char* buf = new char[ length+1 ];
	buf[0] = 0;

	if ( vfread( buf, length, 1, file ) != 1 ) {
		delete [] buf;
		SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN );
		return false;
	}

	return LoadMem(buf, length, encoding);
}
예제 #2
0
bool WDTFile::Load(std::string fn)
{
    std::fstream fh;
    fh.open(fn.c_str(),std::ios_base::in | std::ios_base::binary);
    if(!fh.is_open())
        return false;
    uint32 fs = GetFileSize(fn.c_str());
    ByteBuffer bb(fs);
    bb.resize(fs);
    fh.read((char*)bb.contents(),fs);
    fh.close();
    bb.rpos(0);
    return LoadMem(bb);
}
예제 #3
0
파일: lundump.c 프로젝트: AdiBoy/mtasa-blue
static TString* LoadString(LoadState* S)
{
 size_t size = 0;
 if ( sizeof(size_t) <= SIZE_T_PRECOMPILED_CHUNK )
  LoadVar(S,size);
 else
  LoadMem(S,&size,1,SIZE_T_PRECOMPILED_CHUNK);

 if (size==0)
  return NULL;
 else
 {
  char* s=luaZ_openspace(S->L,S->b,size);
  LoadBlock(S,s,size);
  return luaS_newlstr(S->L,s,size-1);		/* remove trailing '\0' */
 }
}