MCPcopy Create free account
hub / github.com/defold/defold / read_file_to_vec

Function read_file_to_vec

engine/dlib/src/basis/encoder/basisu_enc.cpp:509–560  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 3

load_pngFunction · 0.85
read_tgaFunction · 0.85
opencl_initFunction · 0.85

Calls 1

try_resizeMethod · 0.80

Tested by

no test coverage detected