]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
zstd -d writes to stdout when input is stdin
authorYann Collet <cyan@fb.com>
Thu, 1 Sep 2016 22:05:57 +0000 (15:05 -0700)
committerYann Collet <cyan@fb.com>
Thu, 1 Sep 2016 22:05:57 +0000 (15:05 -0700)
programs/zstdcli.c
tests/playTests.sh

index 2d6d45214a6478d951a93bd5f1f6c2b006b87ce7..57a271ab9fe86f24dcb50ed8ba02f772ebce94ac 100644 (file)
@@ -83,7 +83,7 @@
 
 static const char*    g_defaultDictName = "dictionary";
 static const unsigned g_defaultMaxDictSize = 110 KB;
-static const int      g_defaultDictCLevel = 5;
+static const int      g_defaultDictCLevel = 3;
 static const unsigned g_defaultSelectivityLevel = 9;
 
 
@@ -182,7 +182,7 @@ static void waitEnter(void)
 /*! readU32FromChar() :
     @return : unsigned integer value reach from input in `char` format
     Will also modify `*stringPtr`, advancing it to position where it stopped reading.
-    Note : this function can overflow if result > MAX_UINT */
+    Note : this function can overflow if digit string > MAX_UINT */
 static unsigned readU32FromChar(const char** stringPtr)
 {
     unsigned result = 0;
@@ -289,13 +289,13 @@ int main(int argCount, char** argv)
                 argument++;
 
                 while (argument[0]!=0) {
-    #ifndef ZSTD_NOCOMPRESS
+#ifndef ZSTD_NOCOMPRESS
                     /* compression Level */
                     if ((*argument>='0') && (*argument<='9')) {
                         dictCLevel = cLevel = readU32FromChar(&argument);
                         continue;
                     }
-    #endif
+#endif
 
                     switch(argument[0])
                     {
@@ -337,7 +337,7 @@ int main(int argCount, char** argv)
                         /* recursive */
                     case 'r': recursive=1; argument++; break;
 
-    #ifndef ZSTD_NOBENCH
+#ifndef ZSTD_NOBENCH
                         /* Benchmark */
                     case 'b': bench=1; argument++; break;
 
@@ -368,7 +368,7 @@ int main(int argCount, char** argv)
                             BMK_SetBlockSize(bSize);
                         }
                         break;
-    #endif   /* ZSTD_NOBENCH */
+#endif   /* ZSTD_NOBENCH */
 
                         /* Dictionary Selection level */
                     case 's':
@@ -378,11 +378,11 @@ int main(int argCount, char** argv)
 
                         /* Pause at the end (-p) or set an additional param (-p#) (hidden option) */
                     case 'p': argument++;
-    #ifndef ZSTD_NOBENCH
+#ifndef ZSTD_NOBENCH
                         if ((*argument>='0') && (*argument<='9')) {
                             BMK_setAdditionalParam(readU32FromChar(&argument));
                         } else
-    #endif
+#endif
                             main_pause=1;
                         break;
                         /* unknown command */
@@ -470,7 +470,7 @@ int main(int argCount, char** argv)
 
     /* Check if input/output defined as console; trigger an error in this case */
     if (!strcmp(filenameTable[0], stdinmark) && IS_CONSOLE(stdin) ) CLEAN_RETURN(badusage(programName));
-    if (outFileName && !strcmp(outFileName, stdoutmark) && IS_CONSOLE(stdout) && !(forceStdout && decode))
+    if (outFileName && !strcmp(outFileName, stdoutmark) && IS_CONSOLE(stdout) && strcmp(filenameTable[0], stdinmark) && !(forceStdout && decode))
         CLEAN_RETURN(badusage(programName));
 
     /* user-selected output filename, only possible with a single file */
index b887613f76c008540dc79cf0ea3bd6b361c9f64b..64b3fd95636205711a2db642f74a7d6a6fbe6ae6 100755 (executable)
@@ -41,6 +41,7 @@ $ECHO "\nStarting playTests.sh isWindows=$isWindows"
 [ -n "$ZSTD" ] || die "ZSTD variable must be defined!"
 
 file $ZSTD
+
 $ECHO "\n**** simple tests **** "
 
 ./datagen > tmp
@@ -51,6 +52,8 @@ $ZSTD -99 -f tmp  # too large compression level, automatic sized down
 $ECHO "test : compress to stdout"
 $ZSTD tmp -c > tmpCompressed
 $ZSTD tmp --stdout > tmpCompressed       # long command format
+$ECHO "test : implied stdout when input is stdin"
+$ECHO bob | $ZSTD | $ZSTD -d
 $ECHO "test : null-length file roundtrip"
 $ECHO -n '' | $ZSTD - --stdout | $ZSTD -d --stdout
 $ECHO "test : decompress file with wrong suffix (must fail)"