]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Expand UTIL_requireUserConfirmation to include stdin input check
authorsenhuang42 <senhuang96@fb.com>
Thu, 24 Sep 2020 19:58:06 +0000 (15:58 -0400)
committersenhuang42 <senhuang96@fb.com>
Thu, 24 Sep 2020 19:58:06 +0000 (15:58 -0400)
programs/fileio.c
programs/util.c
programs/util.h

index aa28d05f207dde9c2caf0141c8e271befcdb3bec..bfcb58c277944e6409374190e16c918480035be3 100644 (file)
@@ -662,7 +662,7 @@ FIO_openDstFile(FIO_ctx_t* fCtx, FIO_prefs_t* const prefs,
                     return NULL;
                 }
                 DISPLAY("zstd: %s already exists; ", dstFileName);
-                if (UTIL_requireUserConfirmation("overwrite (y/n) ? ", "Not overwritten  \n", "yY"))
+                if (UTIL_requireUserConfirmation("overwrite (y/n) ? ", "Not overwritten  \n", "yY", fCtx->hasStdinInput))
                     return NULL;
             }
             /* need to unlink */
@@ -859,7 +859,7 @@ static int FIO_removeMultiFilesWarning(FIO_ctx_t* const fCtx, const FIO_prefs_t*
             }
             DISPLAYLEVEL(2, "\nThe concatenated output CANNOT regenerate the original directory tree. ")
             if (prefs->removeSrcFile) {
-                error = g_display_prefs.displayLevel > displayLevelCutoff && UTIL_requireUserConfirmation("This is a destructive operation. Proceed? (y/n): ", "Aborting...", "yY");
+                error = g_display_prefs.displayLevel > displayLevelCutoff && UTIL_requireUserConfirmation("This is a destructive operation. Proceed? (y/n): ", "Aborting...", "yY", fCtx->hasStdinInput);
             }
         }
         DISPLAY("\n");
index 441ccb2358aec5efcbfd9644e0697bcbaa99b91e..fd31ee9e121af4da4a2b11daacbf04fe43c483ae 100644 (file)
@@ -88,9 +88,12 @@ UTIL_STATIC void* UTIL_realloc(void *ptr, size_t size)
 int g_utilDisplayLevel;
 
 int UTIL_requireUserConfirmation(const char* prompt, const char* abortMsg,
-                                          const char* acceptableLetters) {
+                                 const char* acceptableLetters, int hasStdinInput) {
     int ch, result;
 
+    if (hasStdinInput)
+        return 1;
+
     UTIL_DISPLAY("%s", prompt);
     ch = getchar();
     result = 0;
index eeb6a15e2201c1402af5bab1ddf7fe2609b3e3d4..25fa3f53aab424d4d90b647b52237c3fc94eb7d4 100644 (file)
@@ -96,8 +96,9 @@ extern int g_utilDisplayLevel;
 /**
  * Displays a message prompt and returns success (0) if first character from stdin
  * matches any from acceptableLetters. Otherwise, returns failure (1) and displays abortMsg.
+ * If any of the inputs are stdin itself, then automatically return failure (1).
  */
-int UTIL_requireUserConfirmation(const char* prompt, const char* abortMsg, const char* acceptableLetters);
+int UTIL_requireUserConfirmation(const char* prompt, const char* abortMsg, const char* acceptableLetters, int hasStdinInput);
 
 
 /*-****************************************