MCPcopy Create free account
hub / github.com/ValveSoftware/openvr / Path_ReadBinaryFile

Function Path_ReadBinaryFile

src/vrcore/pathtools_public.cpp:616–651  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Purpose: reading and writing files in the vortex directory -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

614// Purpose: reading and writing files in the vortex directory
615//-----------------------------------------------------------------------------
616std::vector<uint8_t> Path_ReadBinaryFile( const std::string & strFilename )
617{
618 FILE *f;
619#if defined( POSIX )
620 f = fopen( strFilename.c_str(), "rb" );
621#else
622 std::wstring wstrFilename = UTF8to16( strFilename.c_str() );
623 // the open operation needs to be sharable, therefore use of _wfsopen instead of _wfopen_s
624 f = _wfsopen( wstrFilename.c_str(), L"rb", _SH_DENYNO );
625#endif
626
627 std::vector<uint8_t> vecFileContents;
628
629 if ( f != NULL )
630 {
631 fseek( f, 0, SEEK_END );
632 int size = ftell( f );
633 if ( size > 0 )
634 {
635 fseek( f, 0, SEEK_SET );
636
637 vecFileContents.resize( size );
638 if ( fread( &vecFileContents[ 0 ], size, 1, f ) == 1 )
639 {
640 }
641 else
642 {
643 vecFileContents.clear();
644 }
645 }
646
647 fclose( f );
648 }
649
650 return vecFileContents ;
651}
652
653
654unsigned char * Path_ReadBinaryFile( const std::string &strFilename, int *pSize )

Callers 1

Path_ReadTextFileFunction · 0.70

Calls 3

resizeMethod · 0.80
clearMethod · 0.80
UTF8to16Function · 0.70

Tested by

no test coverage detected