]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Improves UX for --list command's lack of support for pipes
authorTopher Lubaway <asimplechris@gmail.com>
Mon, 11 Jun 2018 17:13:00 +0000 (10:13 -0700)
committerTopher Lubaway <asimplechris@gmail.com>
Mon, 11 Jun 2018 17:13:00 +0000 (10:13 -0700)
--list does not support piped input
This checks for a terminal and exits 1 with a well formatted
error message if the STDIN is not from a terminal

programs/fileio.c

index b1d2a24159683db5ca6a5b5adc3ec84daa2576bb..a9833ae5e44f3011956f1e19526ec9223dcbab18 100644 (file)
@@ -27,6 +27,7 @@
 #include "platform.h"   /* Large Files support, SET_BINARY_MODE */
 #include "util.h"       /* UTIL_getFileSize, UTIL_isRegularFile */
 #include <stdio.h>      /* fprintf, fopen, fread, _fileno, stdin, stdout */
+#include <unistd.h>     /* isatty */
 #include <stdlib.h>     /* malloc, free */
 #include <string.h>     /* strcmp, strlen */
 #include <errno.h>      /* errno */
@@ -2030,6 +2031,10 @@ static int FIO_listFile(fileInfo_t* total, const char* inFileName, int displayLe
 }
 
 int FIO_listMultipleFiles(unsigned numFiles, const char** filenameTable, int displayLevel){
+    if (!isatty(0))
+        DISPLAYOUT("zstd --list does not support reading from standard input\n");
+        return 1;
+
     if (numFiles == 0) {
         DISPLAYOUT("No files given\n");
         return 0;