1
0
mirror of https://github.com/facebook/zstd.git synced 2025-08-08 17:22:10 +03:00

getFileSize moved to common/util.h

This commit is contained in:
inikep
2016-04-28 12:23:33 +02:00
parent 1007a1fe3d
commit 69fcd7c0ae
10 changed files with 440 additions and 462 deletions

View File

@@ -86,17 +86,14 @@
#include "mem.h"
#include "zstd_static.h"
#include "datagen.h" /* RDG_genBuffer */
#include "datagen.h" /* RDG_genBuffer */
#include "xxhash.h"
#include "util.h" /* UTIL_GetFileSize */
/* *************************************
* Compiler specifics
***************************************/
#if !defined(S_ISREG)
# define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
#endif
#if defined(_MSC_VER)
# define snprintf sprintf_s
#elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L))
@@ -189,34 +186,6 @@ static U64 BMK_clockSpan( BMK_time_t clockStart, BMK_time_t ticksPerSecond )
return BMK_getSpanTimeMicro(ticksPerSecond, clockStart, clockEnd);
}
static U64 BMK_getFileSize(const char* infilename)
{
int r;
#if defined(_MSC_VER)
struct _stat64 statbuf;
r = _stat64(infilename, &statbuf);
#else
struct stat statbuf;
r = stat(infilename, &statbuf);
#endif
if (r || !S_ISREG(statbuf.st_mode)) return 0; /* No good... */
return (U64)statbuf.st_size;
}
static U32 BMK_isDirectory(const char* infilename)
{
int r;
#if defined(_MSC_VER)
struct _stat64 statbuf;
r = _stat64(infilename, &statbuf);
if (!r && (statbuf.st_mode & _S_IFDIR)) return 1;
#else
struct stat statbuf;
r = stat(infilename, &statbuf);
if (!r && S_ISDIR(statbuf.st_mode)) return 1;
#endif
return 0;
}
/* ********************************************************
* Bench functions
@@ -511,7 +480,7 @@ static U64 BMK_getTotalFileSize(const char** fileNamesTable, unsigned nbFiles)
U64 total = 0;
unsigned n;
for (n=0; n<nbFiles; n++)
total += BMK_getFileSize(fileNamesTable[n]);
total += UTIL_getFileSize(fileNamesTable[n]);
return total;
}
@@ -526,8 +495,8 @@ static void BMK_loadFiles(void* buffer, size_t bufferSize,
FILE* f;
unsigned n;
for (n=0; n<nbFiles; n++) {
U64 fileSize = BMK_getFileSize(fileNamesTable[n]);
if (BMK_isDirectory(fileNamesTable[n])) {
U64 fileSize = UTIL_getFileSize(fileNamesTable[n]);
if (UTIL_isDirectory(fileNamesTable[n])) {
DISPLAYLEVEL(2, "Ignoring %s directory... \n", fileNamesTable[n]);
continue;
}
@@ -562,7 +531,7 @@ static void BMK_benchFileTable(const char** fileNamesTable, unsigned nbFiles,
/* Load dictionary */
if (dictFileName != NULL) {
U64 dictFileSize = BMK_getFileSize(dictFileName);
U64 dictFileSize = UTIL_getFileSize(dictFileName);
if (dictFileSize > 64 MB) EXM_THROW(10, "dictionary file %s too large", dictFileName);
dictBufferSize = (size_t)dictFileSize;
dictBuffer = malloc(dictBufferSize);

View File

@@ -53,14 +53,7 @@
#include "mem.h" /* read */
#include "error_private.h"
#include "dibio.h"
/*-*************************************
* Compiler specifics
***************************************/
#if !defined(S_ISREG)
# define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
#endif
#include "util.h" /* UTIL_GetFileSize */
/*-*************************************
@@ -115,27 +108,12 @@ const char* DiB_getErrorName(size_t errorCode) { return ERR_getErrorName(errorCo
/* ********************************************************
* File related operations
**********************************************************/
static unsigned long long DiB_getFileSize(const char* infilename)
{
int r;
#if defined(_MSC_VER)
struct _stat64 statbuf;
r = _stat64(infilename, &statbuf);
#else
struct stat statbuf;
r = stat(infilename, &statbuf);
#endif
if (r || !S_ISREG(statbuf.st_mode)) return 0; /* No good... */
return (unsigned long long)statbuf.st_size;
}
static unsigned long long DiB_getTotalFileSize(const char** fileNamesTable, unsigned nbFiles)
{
unsigned long long total = 0;
unsigned n;
for (n=0; n<nbFiles; n++)
total += DiB_getFileSize(fileNamesTable[n]);
total += UTIL_getFileSize(fileNamesTable[n]);
return total;
}
@@ -150,7 +128,7 @@ static void DiB_loadFiles(void* buffer, size_t bufferSize,
for (n=0; n<nbFiles; n++) {
size_t readSize;
unsigned long long fileSize = DiB_getFileSize(fileNamesTable[n]);
unsigned long long fileSize = UTIL_getFileSize(fileNamesTable[n]);
FILE* f = fopen(fileNamesTable[n], "rb");
if (f==NULL) EXM_THROW(10, "impossible to open file %s", fileNamesTable[n]);
DISPLAYLEVEL(2, "Loading %s... \r", fileNamesTable[n]);

View File

@@ -66,6 +66,7 @@
#include "fileio.h"
#include "zstd_static.h" /* ZSTD_magicNumber, ZSTD_frameHeaderSize_max */
#include "zbuff_static.h"
#include "util.h" /* UTIL_GetFileSize */
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT==1)
# include "zstd_legacy.h" /* ZSTD_isLegacy */
@@ -87,10 +88,6 @@
# define IS_CONSOLE(stdStream) isatty(fileno(stdStream))
#endif
#if !defined(S_ISREG)
# define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
#endif
/*-*************************************
* Constants
@@ -169,21 +166,6 @@ static unsigned FIO_GetMilliSpan(clock_t nPrevious)
}
static U64 FIO_getFileSize(const char* infilename)
{
int r;
#if defined(_MSC_VER)
struct _stat64 statbuf;
r = _stat64(infilename, &statbuf);
#else
struct stat statbuf;
r = stat(infilename, &statbuf);
#endif
if (r || !S_ISREG(statbuf.st_mode)) return 0;
return (U64)statbuf.st_size;
}
static FILE* FIO_openSrcFile(const char* srcFileName)
{
FILE* f;
@@ -252,7 +234,7 @@ static size_t FIO_loadFile(void** bufferPtr, const char* fileName)
DISPLAYLEVEL(4,"Loading %s as dictionary \n", fileName);
fileHandle = fopen(fileName, "rb");
if (fileHandle==0) EXM_THROW(31, "Error opening file %s", fileName);
fileSize = FIO_getFileSize(fileName);
fileSize = UTIL_getFileSize(fileName);
if (fileSize > MAX_DICT_SIZE) {
int seekResult;
if (fileSize > 1 GB) EXM_THROW(32, "Dictionary file %s is too large", fileName); /* avoid extreme cases */
@@ -333,7 +315,7 @@ static int FIO_compressFilename_internal(cRess_t ress,
size_t dictSize = ress.dictBufferSize;
size_t sizeCheck;
ZSTD_parameters params;
U64 const fileSize = FIO_getFileSize(srcFileName);
U64 const fileSize = UTIL_getFileSize(srcFileName);
/* init */
params.cParams = ZSTD_getCParams(cLevel, fileSize, dictSize);

View File

@@ -53,15 +53,7 @@
#include "fse_static.h"
#include "zbuff.h"
#include "datagen.h"
/*_************************************
* Compiler Options
**************************************/
/* S_ISREG & gettimeofday() are not supported by MSVC */
#if !defined(S_ISREG)
# define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
#endif
#include "util.h" /* UTIL_GetFileSize */
/*_************************************
@@ -135,21 +127,6 @@ static size_t BMK_findMaxMem(U64 requiredMem)
}
static U64 BMK_GetFileSize(const char* infilename)
{
int r;
#if defined(_MSC_VER)
struct _stat64 statbuf;
r = _stat64(infilename, &statbuf);
#else
struct stat statbuf;
r = stat(infilename, &statbuf);
#endif
if (r || !S_ISREG(statbuf.st_mode)) return 0; /* No good... */
return (U64)statbuf.st_size;
}
/*_*******************************************************
* Benchmark wrappers
*********************************************************/
@@ -446,7 +423,7 @@ static int benchFiles(const char** fileNamesTable, const int nbFiles, U32 benchN
if (inFile==NULL) { DISPLAY( "Pb opening %s\n", inFileName); return 11; }
/* Memory allocation & restrictions */
inFileSize = BMK_GetFileSize(inFileName);
inFileSize = UTIL_getFileSize(inFileName);
benchedSize = BMK_findMaxMem(inFileSize*3) / 3;
if ((U64)benchedSize > inFileSize) benchedSize = (size_t)inFileSize;
if (benchedSize < inFileSize)

View File

@@ -37,7 +37,7 @@
# define _LARGEFILE64_SOURCE
#endif
/* S_ISREG & gettimeofday() are not supported by MSVC */
/* gettimeofday() are not supported by MSVC */
#if defined(_MSC_VER) || defined(_WIN32)
# define BMK_LEGACY_TIMER 1
#endif
@@ -68,15 +68,7 @@
#include "zstd_static.h"
#include "datagen.h"
#include "xxhash.h"
/*-************************************
* Compiler Options
**************************************/
/* S_ISREG & gettimeofday() are not supported by MSVC */
#if !defined(S_ISREG)
# define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
#endif
#include "util.h" /* UTIL_GetFileSize */
/*-************************************
@@ -197,20 +189,6 @@ static size_t BMK_findMaxMem(U64 requiredMem)
}
static U64 BMK_GetFileSize(char* infilename)
{
int r;
#if defined(_MSC_VER)
struct _stat64 statbuf;
r = _stat64(infilename, &statbuf);
#else
struct stat statbuf;
r = stat(infilename, &statbuf);
#endif
if (r || !S_ISREG(statbuf.st_mode)) return 0; /* No good... */
return (U64)statbuf.st_size;
}
# define FUZ_rotl32(x,r) ((x << r) | (x >> (32 - r)))
U32 FUZ_rand(U32* src)
{
@@ -790,7 +768,7 @@ int benchFiles(char** fileNamesTable, int nbFiles)
}
/* Memory allocation & restrictions */
inFileSize = BMK_GetFileSize(inFileName);
inFileSize = UTIL_getFileSize(inFileName);
benchedSize = BMK_findMaxMem(inFileSize*3) / 3;
if ((U64)benchedSize > inFileSize) benchedSize = (size_t)inFileSize;
if (benchedSize < inFileSize)
@@ -841,7 +819,7 @@ int optimizeForSize(char* inFileName)
}
/* Memory allocation & restrictions */
inFileSize = BMK_GetFileSize(inFileName);
inFileSize = UTIL_getFileSize(inFileName);
benchedSize = (size_t) BMK_findMaxMem(inFileSize*3) / 3;
if ((U64)benchedSize > inFileSize) benchedSize = (size_t)inFileSize;
if (benchedSize < inFileSize)