MCPcopy Create free account
hub / github.com/KhronosGroup/KTX-Software / read_file_to_vec

Function read_file_to_vec

external/basisu/encoder/basisu_enc.cpp:518–569  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

516#endif
517
518 bool read_file_to_vec(const char* pFilename, uint8_vec& data)
519 {
520 FILE* pFile = nullptr;
521#ifdef _WIN32
522 fopen_s(&pFile, pFilename, "rb");
523#else
524 pFile = fopen(pFilename, "rb");
525#endif
526 if (!pFile)
527 return false;
528
529 fseek(pFile, 0, SEEK_END);
530#ifdef _WIN32
531 int64_t filesize = _ftelli64(pFile);
532#else
533 int64_t filesize = ftello(pFile);
534#endif
535 if (filesize < 0)
536 {
537 fclose(pFile);
538 return false;
539 }
540 fseek(pFile, 0, SEEK_SET);
541
542 if (sizeof(size_t) == sizeof(uint32_t))
543 {
544 if (filesize > 0x70000000)
545 {
546 // File might be too big to load safely in one alloc
547 fclose(pFile);
548 return false;
549 }
550 }
551
552 if (!data.try_resize((size_t)filesize))
553 {
554 fclose(pFile);
555 return false;
556 }
557
558 if (filesize)
559 {
560 if (fread(&data[0], 1, (size_t)filesize, pFile) != (size_t)filesize)
561 {
562 fclose(pFile);
563 return false;
564 }
565 }
566
567 fclose(pFile);
568 return true;
569 }
570
571 bool write_data_to_file(const char* pFilename, const void* pData, size_t len)
572 {

Callers 6

load_basis_fileFunction · 0.85
unpack_and_validate_modeFunction · 0.85
load_pngFunction · 0.85
read_tgaFunction · 0.85
opencl_initFunction · 0.85

Calls 1

try_resizeMethod · 0.45

Tested by

no test coverage detected