⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileinputstream.cpp

📁 这个是symbian下的一个蛮庞大的3D游戏源代码!对于学习3D开发的人有很大的帮助!
💻 CPP
字号:
#include "dprintf.h"
#include <io/IOException.h>
#include <io/FileInputStream.h>
#include <lang/Globals.h>
#include <stdio.h>
#include <string.h>
#include <config.h>


using namespace lang;


namespace io
{


FileInputStream::FileInputStream( const char* filename )
{
	String s(filename);
	m_name = s;


#ifdef __SYMBIAN32__
	if ( strlen(filename) >= 255 )
		INTERNAL_ERROR();
	char buf[256];
	strcpy( buf, filename );
	for ( int i = 0 ; buf[i] ; ++i )
		if ( buf[i] == '/' )
			buf[i] = '\\';
	filename = buf;
#endif

	m_fh = fopen( filename, "rb" );
	if ( !m_fh )
	{
		dprintf( "Failed to open file %s\n", filename );
		throwError( IOException(Format("Failed to open file {0}", filename)) );
	}
	dprintf( "File %s open ok\n", filename );
}

FileInputStream::~FileInputStream()
{
	FILE* fh = reinterpret_cast<FILE*>(m_fh);
	if ( fh )
		fclose( fh );
}

int FileInputStream::read( void* data, int size )
{
	FILE* fh = reinterpret_cast<FILE*>(m_fh);

	int bytes = fread( data, 1, size, fh );
	if ( bytes < size && ferror(fh) )
		INTERNAL_ERROR(); //( IOException( Format("Failed to read {1} bytes from {0}", toString(), size) ) );
	return bytes;
}

int FileInputStream::available() const
{
	FILE* fh = reinterpret_cast<FILE*>(m_fh);
	if ( !fh )
		return 0;
	int cur = ftell( fh );
	fseek( fh, 0, SEEK_END );
	int end = ftell( fh );
	fseek( fh, cur, SEEK_SET );
	if ( ferror(fh) )
		INTERNAL_ERROR(); //( IOException( Format("Failed to seek {0}", toString()) ) );
	return end-cur;
}


} // io


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -