diff options
author | Yann Collet <Cyan4973@users.noreply.github.com> | 2022-01-29 01:02:00 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-29 01:02:00 (GMT) |
commit | d27e237b188cdfb7528c7a18696d97d190613559 (patch) | |
tree | 3a8a14d4d6af2cdafef2d46be82613933b598659 /programs/util.h | |
parent | b2256c072ed75d5a557cf635a229752c2852e4e8 (diff) | |
parent | 540b52ea7b8819535ec5f456cf7c6b4792ff1675 (diff) | |
download | lz4-d27e237b188cdfb7528c7a18696d97d190613559.zip lz4-d27e237b188cdfb7528c7a18696d97d190613559.tar.gz lz4-d27e237b188cdfb7528c7a18696d97d190613559.tar.bz2 |
Merge pull request #1048 from Low-power/lz4cli-list-stdin
'--list' doesn't work stdin even it is a regular file
Diffstat (limited to 'programs/util.h')
-rw-r--r-- | programs/util.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/programs/util.h b/programs/util.h index 394837e..2840179 100644 --- a/programs/util.h +++ b/programs/util.h @@ -317,6 +317,7 @@ UTIL_STATIC void UTIL_waitForNextTick(void) UTIL_STATIC int UTIL_isRegFile(const char* infilename); +UTIL_STATIC int UTIL_isRegFD(int fd); UTIL_STATIC int UTIL_setFileStat(const char *filename, stat_t *statbuf) @@ -352,6 +353,19 @@ UTIL_STATIC int UTIL_setFileStat(const char *filename, stat_t *statbuf) } +UTIL_STATIC int UTIL_getFDStat(int fd, stat_t *statbuf) +{ + int r; +#if defined(_MSC_VER) + r = _fstat64(fd, statbuf); + if (r || !(statbuf->st_mode & S_IFREG)) return 0; /* No good... */ +#else + r = fstat(fd, statbuf); + if (r || !S_ISREG(statbuf->st_mode)) return 0; /* No good... */ +#endif + return 1; +} + UTIL_STATIC int UTIL_getFileStat(const char* infilename, stat_t *statbuf) { int r; @@ -366,6 +380,17 @@ UTIL_STATIC int UTIL_getFileStat(const char* infilename, stat_t *statbuf) } +UTIL_STATIC int UTIL_isRegFD(int fd) +{ + stat_t statbuf; +#ifdef _WIN32 + /* Windows runtime library always open file descriptors 0, 1 and 2 in text mode, therefore we can't use them for binary I/O */ + if(fd < 3) return 0; +#endif + 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; |