121 lines
1.6 KiB
C++
121 lines
1.6 KiB
C++
#include "Precompiled.h"
|
|
|
|
|
|
|
|
#include "RakiTests/Stream/WriteFileStream.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace raki
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
WriteFileStream::WriteFileStream()
|
|
: m_file( NULL )
|
|
, m_size( 0 )
|
|
{
|
|
setIsWriting();
|
|
}
|
|
|
|
|
|
WriteFileStream::~WriteFileStream()
|
|
{
|
|
close();
|
|
}
|
|
|
|
bool WriteFileStream::open( const char * _path )
|
|
{
|
|
RAKI_ASSERT( _path );
|
|
|
|
close();
|
|
|
|
#if defined ( _MSC_VER )
|
|
|
|
errno_t err = fopen_s( &m_file, _path, "wb" );
|
|
|
|
if ( err )
|
|
m_file = NULL;
|
|
|
|
#else
|
|
|
|
m_file = fopen( _path, "wb" );
|
|
|
|
#endif
|
|
|
|
return ( m_file != NULL );
|
|
}
|
|
|
|
|
|
void WriteFileStream::close()
|
|
{
|
|
if ( m_file )
|
|
fclose( m_file );
|
|
|
|
m_file = NULL;
|
|
}
|
|
|
|
|
|
u64 WriteFileStream::stream( void * _data, const u64 _size )
|
|
{
|
|
RAKI_ASSERT( _data );
|
|
RAKI_ASSERT( _size );
|
|
|
|
if ( m_file )
|
|
return (u64) fwrite( _data, 1, (size_t)_size, m_file );
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
u64 WriteFileStream::seek( const u64 _size, const SeekType _seekType )
|
|
{
|
|
if ( m_file )
|
|
{
|
|
if ( _seekType == SeekableStream::fromBeginning )
|
|
{
|
|
fseek( m_file, (long)_size, SEEK_SET );
|
|
}
|
|
else if ( _seekType == SeekableStream::fromCurrentPos )
|
|
{
|
|
fseek( m_file, (long)_size, SEEK_CUR );
|
|
}
|
|
else
|
|
{
|
|
RAKI_ASSERT_FALSE;
|
|
}
|
|
|
|
return (u64) ftell( m_file );
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
u64 WriteFileStream::getCurrentPos() const
|
|
{
|
|
if ( m_file )
|
|
return (u64) ftell( m_file );
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
u64 WriteFileStream::getSize() const
|
|
{
|
|
if ( m_file )
|
|
return m_size;
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace raki
|