MCPcopy Create free account
hub / github.com/BinomialLLC/basis_universal / read_file

Function read_file

example_transcoding/utils.cpp:905–946  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

903#endif
904
905bool read_file(const char* pFilename, uint8_vec& buf)
906{
907 buf.resize(0);
908
909 FILE* pFile = nullptr;
910#if _MSC_VER
911 fopen_s(&pFile, pFilename, "rb");
912#else
913 pFile = fopen(pFilename, "rb");
914#endif
915 if (!pFile)
916 return false;
917
918 fseek(pFile, 0, SEEK_END);
919
920 long file_end_ofs = ftell(pFile);
921 if (file_end_ofs <= 0)
922 {
923 fclose(pFile);
924 return false;
925 }
926
927 size_t sz = static_cast<size_t>(file_end_ofs);
928 if (sz != (unsigned long)file_end_ofs)
929 {
930 fclose(pFile);
931 return false;
932 }
933
934 fseek(pFile, 0, SEEK_SET);
935
936 buf.resize(sz);
937
938 if (fread(buf.data(), sizeof(uint8_t), sz, pFile) != sz)
939 {
940 fclose(pFile);
941 return false;
942 }
943
944 fclose(pFile);
945 return true;
946}
947
948} // namespace utils

Callers 1

mainFunction · 0.85

Calls 2

resizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected