mirror of
https://github.com/facebook/zstd.git
synced 2025-12-07 00:02:39 -05:00
Use New Stat Helper
This commit is contained in:
parent
b11bea56a5
commit
69cb9e7798
@ -113,12 +113,7 @@ int UTIL_stat(const char* filename, stat_t* statbuf)
|
|||||||
int UTIL_fileExist(const char* filename)
|
int UTIL_fileExist(const char* filename)
|
||||||
{
|
{
|
||||||
stat_t statbuf;
|
stat_t statbuf;
|
||||||
#if defined(_MSC_VER)
|
return UTIL_stat(filename, &statbuf);
|
||||||
int const stat_error = _stat64(filename, &statbuf);
|
|
||||||
#else
|
|
||||||
int const stat_error = stat(filename, &statbuf);
|
|
||||||
#endif
|
|
||||||
return !stat_error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int UTIL_isRegularFile(const char* infilename)
|
int UTIL_isRegularFile(const char* infilename)
|
||||||
@ -129,27 +124,22 @@ int UTIL_isRegularFile(const char* infilename)
|
|||||||
|
|
||||||
int UTIL_getFileStat(const char* infilename, stat_t *statbuf)
|
int UTIL_getFileStat(const char* infilename, stat_t *statbuf)
|
||||||
{
|
{
|
||||||
int r;
|
const int r = UTIL_stat(infilename, statbuf);
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
r = _stat64(infilename, statbuf);
|
return r && (statbuf->st_mode & S_IFREG);
|
||||||
if (r || !(statbuf->st_mode & S_IFREG)) return 0; /* No good... */
|
|
||||||
#else
|
#else
|
||||||
r = stat(infilename, statbuf);
|
return r && S_ISREG(statbuf->st_mode);
|
||||||
if (r || !S_ISREG(statbuf->st_mode)) return 0; /* No good... */
|
|
||||||
#endif
|
#endif
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int UTIL_getDirectoryStat(const char* infilename, stat_t *statbuf)
|
int UTIL_getDirectoryStat(const char* infilename, stat_t *statbuf)
|
||||||
{
|
{
|
||||||
|
const int r = UTIL_stat(infilename, statbuf);
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
int const r = _stat64(infilename, statbuf);
|
return r && (statbuf->st_mode & _S_IFDIR);
|
||||||
if (!r && (statbuf->st_mode & _S_IFDIR)) return 1;
|
|
||||||
#else
|
#else
|
||||||
int const r = stat(infilename, statbuf);
|
return r && S_ISDIR(statbuf->st_mode);
|
||||||
if (!r && S_ISDIR(statbuf->st_mode)) return 1;
|
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* like chmod, but avoid changing permission of /dev/null */
|
/* like chmod, but avoid changing permission of /dev/null */
|
||||||
@ -254,23 +244,17 @@ int UTIL_isLink(const char* infilename)
|
|||||||
|
|
||||||
U64 UTIL_getFileSize(const char* infilename)
|
U64 UTIL_getFileSize(const char* infilename)
|
||||||
{
|
{
|
||||||
|
stat_t statbuf;
|
||||||
|
if (!UTIL_stat(infilename, &statbuf)) return UTIL_FILESIZE_UNKNOWN;
|
||||||
if (!UTIL_isRegularFile(infilename)) return UTIL_FILESIZE_UNKNOWN;
|
if (!UTIL_isRegularFile(infilename)) return UTIL_FILESIZE_UNKNOWN;
|
||||||
{ int r;
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
struct __stat64 statbuf;
|
if (!(statbuf.st_mode & S_IFREG)) return UTIL_FILESIZE_UNKNOWN;
|
||||||
r = _stat64(infilename, &statbuf);
|
|
||||||
if (r || !(statbuf.st_mode & S_IFREG)) return UTIL_FILESIZE_UNKNOWN;
|
|
||||||
#elif defined(__MINGW32__) && defined (__MSVCRT__)
|
#elif defined(__MINGW32__) && defined (__MSVCRT__)
|
||||||
struct _stati64 statbuf;
|
if (!(statbuf.st_mode & S_IFREG)) return UTIL_FILESIZE_UNKNOWN;
|
||||||
r = _stati64(infilename, &statbuf);
|
|
||||||
if (r || !(statbuf.st_mode & S_IFREG)) return UTIL_FILESIZE_UNKNOWN;
|
|
||||||
#else
|
#else
|
||||||
struct stat statbuf;
|
if (!S_ISREG(statbuf.st_mode)) return UTIL_FILESIZE_UNKNOWN;
|
||||||
r = stat(infilename, &statbuf);
|
|
||||||
if (r || !S_ISREG(statbuf.st_mode)) return UTIL_FILESIZE_UNKNOWN;
|
|
||||||
#endif
|
#endif
|
||||||
return (U64)statbuf.st_size;
|
return (U64)statbuf.st_size;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user