]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
bench.c: ignore directories from a file list for benchmark
authorinikep <inikep@gmail.com>
Wed, 13 Apr 2016 08:48:04 +0000 (10:48 +0200)
committerinikep <inikep@gmail.com>
Wed, 13 Apr 2016 08:48:04 +0000 (10:48 +0200)
programs/bench.c

index fcc0934ae261f6f894154387e0e1d3680fc33199..bb03c0b35544c9835a0a00881e8e0a1b100ee0d0 100644 (file)
@@ -500,10 +500,21 @@ static void BMK_loadFiles(void* buffer, size_t bufferSize,
                           size_t* fileSizes,
                           const char** fileNamesTable, unsigned nbFiles)
 {
-    size_t pos = 0;
+    size_t pos = 0, totalSize = 0;
 
     unsigned n;
     for (n=0; n<nbFiles; n++) {
+#if defined(_MSC_VER)
+        struct _stat64 statbuf;
+        int r = _stat64(fileNamesTable[n], &statbuf);
+#else
+        struct stat statbuf;
+        int r = stat(fileNamesTable[n], &statbuf);
+#endif
+        if (!r && S_ISDIR(statbuf.st_mode)) {
+            DISPLAYLEVEL(2, "Ignoring %s directory...       \n", fileNamesTable[n]);
+            continue;
+        }
         U64 fileSize = BMK_getFileSize(fileNamesTable[n]);
         FILE* const f = fopen(fileNamesTable[n], "rb");
         if (f==NULL) EXM_THROW(10, "impossible to open file %s", fileNamesTable[n]);
@@ -513,8 +524,11 @@ static void BMK_loadFiles(void* buffer, size_t bufferSize,
           if (readSize != (size_t)fileSize) EXM_THROW(11, "could not read %s", fileNamesTable[n]);
           pos += readSize; }
         fileSizes[n] = (size_t)fileSize;
+        totalSize += (size_t)fileSize;
         fclose(f);
     }
+    
+    if (totalSize == 0) EXM_THROW(12, "no data to bench");
 }
 
 static void BMK_benchFileTable(const char** fileNamesTable, unsigned nbFiles,