From a51521916d5cdf8930405f4cf3c0ff9c4d5b6a6c Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sun, 26 Feb 2023 20:12:59 -0800 Subject: merge into a single UTIL_isDirectory() method --- programs/lz4io.c | 9 +++++---- programs/util.h | 21 ++------------------- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/programs/lz4io.c b/programs/lz4io.c index 09d906e..dcdf6af 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -328,7 +328,7 @@ static FILE* LZ4IO_openSrcFile(const char* srcFileName) return f; } - if (UTIL_isDir(srcFileName)) { + if (UTIL_isDirectory(srcFileName)) { DISPLAYLEVEL(1, "lz4: %s is a directory -- ignored \n", srcFileName); return NULL; } @@ -387,7 +387,6 @@ LZ4IO_openDstFile(const char* dstFileName, const LZ4IO_prefs_t* const prefs) } - /*************************************** * Legacy Compression ***************************************/ @@ -415,8 +414,10 @@ static int LZ4IO_LZ4_compress(const char* src, char* dst, int srcSize, int dstSi /* LZ4IO_compressFilename_Legacy : * This function is intentionally "hidden" (not published in .h) * It generates compressed streams using the old 'legacy' format */ -int LZ4IO_compressFilename_Legacy(const char* input_filename, const char* output_filename, - int compressionlevel, const LZ4IO_prefs_t* prefs) +int LZ4IO_compressFilename_Legacy(const char* input_filename, + const char* output_filename, + int compressionlevel, + const LZ4IO_prefs_t* prefs) { typedef int (*compress_f)(const char* src, char* dst, int srcSize, int dstSize, int cLevel); compress_f const compressionFunction = (compressionlevel < 3) ? LZ4IO_LZ4_compress : LZ4_compress_HC; diff --git a/programs/util.h b/programs/util.h index f1d8a92..4861049 100644 --- a/programs/util.h +++ b/programs/util.h @@ -198,7 +198,7 @@ UTIL_STATIC void* UTIL_realloc(void* ptr, size_t size) /* supports a==NULL or b==NULL */ UTIL_STATIC int UTIL_sameString(const char* a, const char* b) { - assert(a!=NULL && b!=NULL); /* unsupported scenario */ + assert(a != NULL || b != NULL); /* unsupported scenario */ if (a==NULL) return 0; if (b==NULL) return 0; return !strcmp(a,b); @@ -409,7 +409,6 @@ UTIL_STATIC int UTIL_getFileStat(const char* infilename, stat_t *statbuf) return 1; } - UTIL_STATIC int UTIL_isRegFD(int fd) { stat_t statbuf; @@ -420,14 +419,13 @@ UTIL_STATIC int UTIL_isRegFD(int fd) return UTIL_getFDStat(fd, &statbuf); /* Only need to know whether it is a regular file */ } - UTIL_STATIC int UTIL_isRegFile(const char* infilename) { stat_t statbuf; return UTIL_getFileStat(infilename, &statbuf); /* Only need to know whether it is a regular file */ } -UTIL_STATIC int UTIL_isDir(const char* infilename) +UTIL_STATIC int UTIL_isDirectory(const char* infilename) { stat_t statbuf; int r; @@ -443,21 +441,6 @@ UTIL_STATIC int UTIL_isDir(const char* infilename) } -UTIL_STATIC U32 UTIL_isDirectory(const char* infilename) -{ - int r; - stat_t statbuf; -#if defined(_MSC_VER) - r = _stat64(infilename, &statbuf); - if (!r && (statbuf.st_mode & _S_IFDIR)) return 1; -#else - r = stat(infilename, &statbuf); - if (!r && S_ISDIR(statbuf.st_mode)) return 1; -#endif - return 0; -} - - UTIL_STATIC U64 UTIL_getOpenFileSize(FILE* file) { int r; -- cgit v0.12