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

Function Path_ReadBinaryFile

samples/shared/pathtools.cpp:559–594  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

557// Purpose: reading and writing files in the vortex directory
558//-----------------------------------------------------------------------------
559unsigned char * Path_ReadBinaryFile( const std::string &strFilename, int *pSize )
560{
561 FILE *f;
562#if defined( POSIX )
563 f = fopen( strFilename.c_str(), "rb" );
564#else
565 std::wstring wstrFilename = UTF8to16( strFilename.c_str() );
566 // the open operation needs to be sharable, therefore use of _wfsopen instead of _wfopen_s
567 f = _wfsopen( wstrFilename.c_str(), L"rb", _SH_DENYNO );
568#endif
569
570 unsigned char* buf = NULL;
571
572 if ( f != NULL )
573 {
574 fseek(f, 0, SEEK_END);
575 int size = ftell(f);
576 fseek(f, 0, SEEK_SET);
577
578 buf = new unsigned char[size];
579 if (buf && fread(buf, size, 1, f) == 1)
580 {
581 if (pSize)
582 *pSize = size;
583 }
584 else
585 {
586 delete[] buf;
587 buf = 0;
588 }
589
590 fclose(f);
591 }
592
593 return buf;
594}
595
596uint32_t Path_ReadBinaryFile( const std::string &strFilename, unsigned char *pBuffer, uint32_t unSize )
597{

Callers 1

Path_ReadTextFileFunction · 0.70

Calls 1

UTF8to16Function · 0.70

Tested by

no test coverage detected