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

Function Path_ReadTextFile

samples/shared/pathtools.cpp:659–682  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

657}
658
659std::string Path_ReadTextFile( const std::string &strFilename )
660{
661 // doing it this way seems backwards, but I don't
662 // see an easy way to do this with C/C++ style IO
663 // that isn't worse...
664 int size;
665 unsigned char* buf = Path_ReadBinaryFile( strFilename, &size );
666 if (!buf)
667 return "";
668
669 // convert CRLF -> LF
670 size_t outsize = 1;
671 for (int i=1; i < size; i++)
672 {
673 if (buf[i] == '\n' && buf[i-1] == '\r') // CRLF
674 buf[outsize-1] = '\n'; // ->LF
675 else
676 buf[outsize++] = buf[i]; // just copy
677 }
678
679 std::string ret((char *)buf, outsize);
680 delete[] buf;
681 return ret;
682}
683
684
685bool Path_WriteStringToTextFile( const std::string &strFilename, const char *pchData )

Callers

nothing calls this directly

Calls 1

Path_ReadBinaryFileFunction · 0.70

Tested by

no test coverage detected