protecting "/dev/null" from having its permissions changed.
also : minor : improved consistency of util.h API
#if defined(_WIN32) || defined(WIN32)
/* windows doesn't allow remove read-only files,
* so try to make it writable first */
- chmod(path, _S_IWRITE);
+ UTIL_chmod(path, _S_IWRITE);
#endif
return remove(path);
}
}
if (!UTIL_isRegularFile(srcFileName)
-#ifndef _MSC_VER
- && !UTIL_isFIFO(srcFileName)
-#endif /* _MSC_VER */
+ && !UTIL_isFIFO(srcFileName)
) {
DISPLAYLEVEL(1, "zstd: %s is not a regular file -- ignored \n",
srcFileName);
&& strcmp (srcFileName, stdinmark)
&& strcmp(dstFileName, nulmark) ) {
/* reduce rights on newly created dst file while compression is ongoing */
- chmod(dstFileName, 00600);
+ UTIL_chmod(dstFileName, 00600);
}
return f;
}
#include <direct.h> /* needed for _mkdir in windows */
#endif
+#if defined(_MSC_VER)
+ #define chmod _chmod
+#endif
+
+
+/*-*************************************
+* Constants
+***************************************/
+#define LIST_SIZE_INCREASE (8*1024)
+
+
+/*-*************************************
+* Functions
+***************************************/
+
int UTIL_fileExist(const char* filename)
{
stat_t statbuf;
return 1;
}
+/* like chmod, but avoid changing permission of /dev/null */
+int UTIL_chmod(char const* filename, mode_t permissions)
+{
+ if (!strcmp(filename, "/dev/null")) return 0; /* pretend success, but don't change anything */
+ return chmod(filename, permissions);
+}
+
int UTIL_setFileStat(const char *filename, stat_t *statbuf)
{
int res = 0;
res += chown(filename, statbuf->st_uid, statbuf->st_gid); /* Copy ownership */
#endif
- res += chmod(filename, statbuf->st_mode & 07777); /* Copy file permissions */
+ res += UTIL_chmod(filename, statbuf->st_mode & 07777); /* Copy file permissions */
errno = 0;
return -res; /* number of errors is returned */
}
-U32 UTIL_isDirectory(const char* infilename)
+int UTIL_isDirectory(const char* infilename)
{
- int r;
stat_t statbuf;
#if defined(_MSC_VER)
- r = _stat64(infilename, &statbuf);
+ int const r = _stat64(infilename, &statbuf);
if (!r && (statbuf.st_mode & _S_IFDIR)) return 1;
#else
- r = stat(infilename, &statbuf);
+ int const r = stat(infilename, &statbuf);
if (!r && S_ISDIR(statbuf.st_mode)) return 1;
#endif
return 0;
#endif
}
-#ifndef _MSC_VER
-/* Using this to distinguish named pipes */
-U32 UTIL_isFIFO(const char* infilename)
+/* UTIL_isFIFO : distinguish named pipes */
+int UTIL_isFIFO(const char* infilename)
{
/* macro guards, as defined in : https://linux.die.net/man/2/lstat */
#if PLATFORM_POSIX_VERSION >= 200112L
stat_t statbuf;
- int r = UTIL_getFileStat(infilename, &statbuf);
+ int const r = UTIL_getFileStat(infilename, &statbuf);
if (!r && S_ISFIFO(statbuf.st_mode)) return 1;
#endif
(void)infilename;
return 0;
}
-#endif
-U32 UTIL_isLink(const char* infilename)
+int UTIL_isLink(const char* infilename)
{
/* macro guards, as defined in : https://linux.die.net/man/2/lstat */
#if PLATFORM_POSIX_VERSION >= 200112L
- int r;
stat_t statbuf;
- r = lstat(infilename, &statbuf);
+ int const r = lstat(infilename, &statbuf);
if (!r && S_ISLNK(statbuf.st_mode)) return 1;
#endif
(void)infilename;
# include <io.h> /* _chmod */
#else
# include <unistd.h> /* chown, stat */
-#if PLATFORM_POSIX_VERSION < 200809L
-# include <utime.h> /* utime */
-#else
-# include <fcntl.h> /* AT_FDCWD */
-# include <sys/stat.h> /* utimensat */
-#endif
+# if PLATFORM_POSIX_VERSION < 200809L
+# include <utime.h> /* utime */
+# else
+# include <fcntl.h> /* AT_FDCWD */
+# include <sys/stat.h> /* utimensat */
+# endif
#endif
#include <time.h> /* clock_t, clock, CLOCKS_PER_SEC, nanosleep */
#include "mem.h" /* U32, U64 */
#endif
-/*-*************************************
-* Constants
-***************************************/
-#define LIST_SIZE_INCREASE (8*1024)
-
-
/*-****************************************
* Compiler specifics
******************************************/
* File functions
******************************************/
#if defined(_MSC_VER)
- #define chmod _chmod
typedef struct __stat64 stat_t;
#else
typedef struct stat stat_t;
int UTIL_fileExist(const char* filename);
int UTIL_isRegularFile(const char* infilename);
-int UTIL_setFileStat(const char* filename, stat_t* statbuf);
-U32 UTIL_isDirectory(const char* infilename);
-int UTIL_getFileStat(const char* infilename, stat_t* statbuf);
+int UTIL_isDirectory(const char* infilename);
int UTIL_isSameFile(const char* file1, const char* file2);
-int UTIL_compareStr(const void *p1, const void *p2);
int UTIL_isCompressedFile(const char* infilename, const char *extensionList[]);
-const char* UTIL_getFileExtension(const char* infilename);
+int UTIL_isLink(const char* infilename);
+int UTIL_isFIFO(const char* infilename);
-#ifndef _MSC_VER
-U32 UTIL_isFIFO(const char* infilename);
-#endif
-U32 UTIL_isLink(const char* infilename);
#define UTIL_FILESIZE_UNKNOWN ((U64)(-1))
U64 UTIL_getFileSize(const char* infilename);
-
U64 UTIL_getTotalFileSize(const char* const * const fileNamesTable, unsigned nbFiles);
+int UTIL_getFileStat(const char* infilename, stat_t* statbuf);
+int UTIL_setFileStat(const char* filename, stat_t* statbuf);
+int UTIL_chmod(char const* filename, mode_t permissions); /*< like chmod, but avoid changing permission of /dev/null */
+int UTIL_compareStr(const void *p1, const void *p2);
+const char* UTIL_getFileExtension(const char* infilename);
+
/*
* A modified version of realloc().
* If UTIL_realloc() fails the original block is freed.
*/
-UTIL_STATIC void* UTIL_realloc(void *ptr, size_t size)
+UTIL_STATIC void* UTIL_realloc(void* ptr, size_t size)
{
- void *newptr = realloc(ptr, size);
+ void* const newptr = realloc(ptr, size);
if (newptr) return newptr;
free(ptr);
return NULL;
if (!followLinks) {
unsigned u;
for (u=0, fileNamesNb=0; u<filenameIdx; u++) {
- if (UTIL_isLink(filenameTable[u])
-#ifndef _MSC_VER
- && !UTIL_isFIFO(filenameTable[u])
-#endif /* _MSC_VER */
+ if ( UTIL_isLink(filenameTable[u])
+ && !UTIL_isFIFO(filenameTable[u])
) {
DISPLAYLEVEL(2, "Warning : %s is a symbolic link, ignoring\n", filenameTable[u]);
} else {
filenameTable[fileNamesNb++] = filenameTable[u];
- }
- }
+ } }
if (fileNamesNb == 0 && filenameIdx > 0)
CLEAN_RETURN(1);
filenameIdx = fileNamesNb;
free((void*)filenameTable);
filenameTable = extendedFileList;
filenameIdx = fileNamesNb;
- }
- }
+ } }
#else
(void)followLinks;
#endif
DISPLAYLEVEL(3, "Benchmarking %s \n", filenameTable[i]);
for(c = cLevel; c <= cLevelLast; c++) {
BMK_benchFilesAdvanced(&filenameTable[i], 1, dictFileName, c, &compressionParams, g_displayLevel, &benchParams);
- }
- }
+ } }
} else {
for(; cLevel <= cLevelLast; cLevel++) {
BMK_benchFilesAdvanced(filenameTable, filenameIdx, dictFileName, cLevel, &compressionParams, g_displayLevel, &benchParams);
- }
- }
+ } }
} else {
for(; cLevel <= cLevelLast; cLevel++) {
BMK_syntheticTest(cLevel, compressibility, &compressionParams, g_displayLevel, &benchParams);
- }
- }
+ } }
#else
(void)bench_nbSeconds; (void)blockSize; (void)setRealTimePrio; (void)separateFiles; (void)compressibility;