1
0
mirror of https://github.com/facebook/zstd.git synced 2025-07-29 11:21:22 +03:00

Merge branch 'dev' into ahmed_file

This commit is contained in:
Yann Collet
2019-11-26 11:20:26 -08:00
52 changed files with 1614 additions and 391 deletions

View File

@ -44,7 +44,6 @@ extern "C" {
exit(1); \
} }
/*
* A modified version of realloc().
* If UTIL_realloc() fails the original block is freed.
@ -57,6 +56,10 @@ UTIL_STATIC void* UTIL_realloc(void *ptr, size_t size)
return NULL;
}
#if defined(_MSC_VER)
#define chmod _chmod
#endif
/*-****************************************
* Console log
@ -64,9 +67,16 @@ UTIL_STATIC void* UTIL_realloc(void *ptr, size_t size)
int g_utilDisplayLevel;
/*-****************************************
* Public API
******************************************/
/*-*************************************
* Constants
***************************************/
#define LIST_SIZE_INCREASE (8*1024)
#define MAX_FILE_OF_FILE_NAMES_SIZE (1<<20)*50
/*-*************************************
* Functions
***************************************/
int UTIL_fileExist(const char* filename)
{
@ -98,6 +108,13 @@ int UTIL_getFileStat(const char* infilename, 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;
@ -117,7 +134,7 @@ int UTIL_setFileStat(const char *filename, stat_t *statbuf)
{
/* (atime, mtime) */
struct timespec timebuf[2] = { {0, UTIME_NOW} };
timebuf[1] = statbuf->st_mtim;
timebuf[1].tv_sec = statbuf->st_mtime;
res += utimensat(AT_FDCWD, filename, timebuf, 0);
}
#endif
@ -126,21 +143,20 @@ int UTIL_setFileStat(const char *filename, stat_t *statbuf)
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;
@ -170,28 +186,25 @@ int UTIL_isSameFile(const char* fName1, const char* fName2)
#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;