MCPcopy Create free account
hub / github.com/F-Stack/f-stack / BMK_loadFiles

Function BMK_loadFiles

freebsd/contrib/zstd/zlibWrapper/examples/zwrapbench.c:677–709  ·  view source on GitHub ↗

! BMK_loadFiles() : Loads `buffer` with content of files listed within `fileNamesTable`. At most, fills `buffer` entirely */

Source from the content-addressed store, hash-verified

675 Loads `buffer` with content of files listed within `fileNamesTable`.
676 At most, fills `buffer` entirely */
677static void BMK_loadFiles(void* buffer, size_t bufferSize,
678 size_t* fileSizes,
679 const char** fileNamesTable, unsigned nbFiles)
680{
681 size_t pos = 0, totalSize = 0;
682 unsigned n;
683 for (n=0; n<nbFiles; n++) {
684 FILE* f;
685 U64 fileSize = UTIL_getFileSize(fileNamesTable[n]);
686 if (UTIL_isDirectory(fileNamesTable[n])) {
687 DISPLAYLEVEL(2, "Ignoring %s directory... \n", fileNamesTable[n]);
688 fileSizes[n] = 0;
689 continue;
690 }
691 if (fileSize == UTIL_FILESIZE_UNKNOWN) {
692 DISPLAYLEVEL(2, "Cannot determine size of %s ... \n", fileNamesTable[n]);
693 fileSizes[n] = 0;
694 continue;
695 }
696 f = fopen(fileNamesTable[n], "rb");
697 if (f==NULL) EXM_THROW(10, "impossible to open file %s", fileNamesTable[n]);
698 DISPLAYUPDATE(2, "Loading %s... \r", fileNamesTable[n]);
699 if (fileSize > bufferSize-pos) fileSize = bufferSize-pos, nbFiles=n; /* buffer too small - stop after this file */
700 { size_t const readSize = fread(((char*)buffer)+pos, 1, (size_t)fileSize, f);
701 if (readSize != (size_t)fileSize) EXM_THROW(11, "could not read %s", fileNamesTable[n]);
702 pos += readSize; }
703 fileSizes[n] = (size_t)fileSize;
704 totalSize += (size_t)fileSize;
705 fclose(f);
706 }
707
708 if (totalSize == 0) EXM_THROW(12, "no data to bench");
709}
710
711static void BMK_benchFileTable(const char** fileNamesTable, unsigned nbFiles,
712 const char* dictFileName, int cLevel, int cLevelLast)

Callers 1

BMK_benchFileTableFunction · 0.70

Calls 2

UTIL_getFileSizeFunction · 0.85
UTIL_isDirectoryFunction · 0.85

Tested by

no test coverage detected