Multi-OS support for --list detecting stream input
IS_CONSOLE stolen wholesale from Options.cpp not sure if i should have extracted that code for DRY-ness tested in OSX and functionality seems appropriate unstested in a windows environmentdev
parent
881defaeb3
commit
88ae51acb3
|
@ -31,13 +31,6 @@
|
|||
#include <string.h> /* strcmp, strlen */
|
||||
#include <errno.h> /* errno */
|
||||
|
||||
#if defined (_MSC_VER)
|
||||
# include <sys/stat.h>
|
||||
# include <io.h>
|
||||
#else
|
||||
# include <unistd.h> /* isatty */
|
||||
#endif
|
||||
|
||||
#include "mem.h"
|
||||
#include "fileio.h"
|
||||
#include "util.h"
|
||||
|
@ -64,6 +57,19 @@
|
|||
# include <lz4.h>
|
||||
#endif
|
||||
|
||||
// Multi-OS support for determining if terminal is tty
|
||||
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || \
|
||||
defined(__CYGWIN__)
|
||||
#include <io.h> /* _isatty */
|
||||
#define IS_CONSOLE(stdStream) _isatty(_fileno(stdStream))
|
||||
#elif defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || defined(_POSIX_SOURCE) || (defined(__APPLE__) && defined(__MACH__)) || \
|
||||
defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) /* https://sourceforge.net/p/predef/wiki/OperatingSystems/ */
|
||||
#include <unistd.h> /* isatty */
|
||||
#define IS_CONSOLE(stdStream) isatty(fileno(stdStream))
|
||||
#else
|
||||
#define IS_CONSOLE(stdStream) 0
|
||||
#endif
|
||||
|
||||
|
||||
/*-*************************************
|
||||
* Constants
|
||||
|
@ -2032,14 +2038,11 @@ static int FIO_listFile(fileInfo_t* total, const char* inFileName, int displayLe
|
|||
}
|
||||
|
||||
int FIO_listMultipleFiles(unsigned numFiles, const char** filenameTable, int displayLevel){
|
||||
// isatty comes from the header unistd.h
|
||||
// windows has no equilivant
|
||||
#if !defined(_MSC_VER)
|
||||
if (!isatty(0)) {
|
||||
|
||||
if (!IS_CONSOLE(stdin)) {
|
||||
DISPLAYOUT("zstd: --list does not support reading from standard input\n");
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (numFiles == 0) {
|
||||
DISPLAYOUT("No files given\n");
|
||||
|
|
Loading…
Reference in New Issue