diff --git a/programs/fileio.c b/programs/fileio.c index aa28d05f..bfcb58c2 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -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"); diff --git a/programs/util.c b/programs/util.c index 441ccb23..fd31ee9e 100644 --- a/programs/util.c +++ b/programs/util.c @@ -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; diff --git a/programs/util.h b/programs/util.h index eeb6a15e..25fa3f53 100644 --- a/programs/util.h +++ b/programs/util.h @@ -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); /*-****************************************