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

Function BMK_loadFiles

freebsd/contrib/zstd/programs/benchzstd.c:748–782  ·  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

746 * Loads `buffer` with content of files listed within `fileNamesTable`.
747 * At most, fills `buffer` entirely. */
748static int BMK_loadFiles(void* buffer, size_t bufferSize,
749 size_t* fileSizes,
750 const char* const * fileNamesTable, unsigned nbFiles,
751 int displayLevel)
752{
753 size_t pos = 0, totalSize = 0;
754 unsigned n;
755 for (n=0; n<nbFiles; n++) {
756 U64 fileSize = UTIL_getFileSize(fileNamesTable[n]); /* last file may be shortened */
757 if (UTIL_isDirectory(fileNamesTable[n])) {
758 DISPLAYLEVEL(2, "Ignoring %s directory... \n", fileNamesTable[n]);
759 fileSizes[n] = 0;
760 continue;
761 }
762 if (fileSize == UTIL_FILESIZE_UNKNOWN) {
763 DISPLAYLEVEL(2, "Cannot evaluate size of %s, ignoring ... \n", fileNamesTable[n]);
764 fileSizes[n] = 0;
765 continue;
766 }
767 { FILE* const f = fopen(fileNamesTable[n], "rb");
768 if (f==NULL) RETURN_ERROR_INT(10, "impossible to open file %s", fileNamesTable[n]);
769 DISPLAYUPDATE(2, "Loading %s... \r", fileNamesTable[n]);
770 if (fileSize > bufferSize-pos) fileSize = bufferSize-pos, nbFiles=n; /* buffer too small - stop after this file */
771 { size_t const readSize = fread(((char*)buffer)+pos, 1, (size_t)fileSize, f);
772 if (readSize != (size_t)fileSize) RETURN_ERROR_INT(11, "could not read %s", fileNamesTable[n]);
773 pos += readSize;
774 }
775 fileSizes[n] = (size_t)fileSize;
776 totalSize += (size_t)fileSize;
777 fclose(f);
778 } }
779
780 if (totalSize == 0) RETURN_ERROR_INT(12, "no data to bench");
781 return 0;
782}
783
784BMK_benchOutcome_t BMK_benchFilesAdvanced(
785 const char* const * fileNamesTable, unsigned nbFiles,

Callers 1

BMK_benchFilesAdvancedFunction · 0.70

Calls 2

UTIL_getFileSizeFunction · 0.85
UTIL_isDirectoryFunction · 0.85

Tested by

no test coverage detected