Deduplicate Some Low-Hanging Fruit of Redundant Stat Calls
This commit is contained in:
parent
44fa052599
commit
7238cca1a1
@ -519,6 +519,7 @@ static int FIO_remove(const char* path)
|
|||||||
* @result : FILE* to `srcFileName`, or NULL if it fails */
|
* @result : FILE* to `srcFileName`, or NULL if it fails */
|
||||||
static FILE* FIO_openSrcFile(const char* srcFileName)
|
static FILE* FIO_openSrcFile(const char* srcFileName)
|
||||||
{
|
{
|
||||||
|
stat_t statbuf;
|
||||||
assert(srcFileName != NULL);
|
assert(srcFileName != NULL);
|
||||||
if (!strcmp (srcFileName, stdinmark)) {
|
if (!strcmp (srcFileName, stdinmark)) {
|
||||||
DISPLAYLEVEL(4,"Using stdin for input \n");
|
DISPLAYLEVEL(4,"Using stdin for input \n");
|
||||||
@ -526,14 +527,14 @@ static FILE* FIO_openSrcFile(const char* srcFileName)
|
|||||||
return stdin;
|
return stdin;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!UTIL_fileExist(srcFileName)) {
|
if (!UTIL_stat(srcFileName, &statbuf)) {
|
||||||
DISPLAYLEVEL(1, "zstd: can't stat %s : %s -- ignored \n",
|
DISPLAYLEVEL(1, "zstd: can't stat %s : %s -- ignored \n",
|
||||||
srcFileName, strerror(errno));
|
srcFileName, strerror(errno));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!UTIL_isRegularFile(srcFileName)
|
if (!UTIL_isRegularFileStat(&statbuf)
|
||||||
&& !UTIL_isFIFO(srcFileName)
|
&& !UTIL_isFIFOStat(&statbuf)
|
||||||
) {
|
) {
|
||||||
DISPLAYLEVEL(1, "zstd: %s is not a regular file -- ignored \n",
|
DISPLAYLEVEL(1, "zstd: %s is not a regular file -- ignored \n",
|
||||||
srcFileName);
|
srcFileName);
|
||||||
|
@ -354,11 +354,12 @@ UTIL_createFileNamesTable_fromFileName(const char* inputFileName)
|
|||||||
char* buf;
|
char* buf;
|
||||||
size_t bufSize;
|
size_t bufSize;
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
|
stat_t statbuf;
|
||||||
|
|
||||||
if (!UTIL_fileExist(inputFileName) || !UTIL_isRegularFile(inputFileName))
|
if (!UTIL_stat(inputFileName, &statbuf) || !UTIL_isRegularFileStat(&statbuf))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
{ U64 const inputFileSize = UTIL_getFileSize(inputFileName);
|
{ U64 const inputFileSize = UTIL_getFileSizeStat(&statbuf);
|
||||||
if(inputFileSize > MAX_FILE_OF_FILE_NAMES_SIZE)
|
if(inputFileSize > MAX_FILE_OF_FILE_NAMES_SIZE)
|
||||||
return NULL;
|
return NULL;
|
||||||
bufSize = (size_t)(inputFileSize + 1); /* (+1) to add '\0' at the end of last filename */
|
bufSize = (size_t)(inputFileSize + 1); /* (+1) to add '\0' at the end of last filename */
|
||||||
|
Loading…
Reference in New Issue
Block a user