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 environment
This commit is contained in:
+15
-12
@@ -31,13 +31,6 @@
|
|||||||
#include <string.h> /* strcmp, strlen */
|
#include <string.h> /* strcmp, strlen */
|
||||||
#include <errno.h> /* errno */
|
#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 "mem.h"
|
||||||
#include "fileio.h"
|
#include "fileio.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
@@ -64,6 +57,19 @@
|
|||||||
# include <lz4.h>
|
# include <lz4.h>
|
||||||
#endif
|
#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
|
* 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){
|
int FIO_listMultipleFiles(unsigned numFiles, const char** filenameTable, int displayLevel){
|
||||||
// isatty comes from the header unistd.h
|
|
||||||
// windows has no equilivant
|
if (!IS_CONSOLE(stdin)) {
|
||||||
#if !defined(_MSC_VER)
|
|
||||||
if (!isatty(0)) {
|
|
||||||
DISPLAYOUT("zstd: --list does not support reading from standard input\n");
|
DISPLAYOUT("zstd: --list does not support reading from standard input\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
if (numFiles == 0) {
|
if (numFiles == 0) {
|
||||||
DISPLAYOUT("No files given\n");
|
DISPLAYOUT("No files given\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user