From 56aa77d51bb3e1a359f6df1cb8476e5e54e5dc38 Mon Sep 17 00:00:00 2001 From: human Date: Thu, 2 May 2019 20:15:09 +0300 Subject: [PATCH] xbps-install: make question() read the whole input line reading only the first character would answer the next question() with the next character (unless you just pressed enter) --- bin/xbps-install/question.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/bin/xbps-install/question.c b/bin/xbps-install/question.c index bb74214b..865649ff 100644 --- a/bin/xbps-install/question.c +++ b/bin/xbps-install/question.c @@ -41,22 +41,27 @@ static bool question(bool preset, const char *fmt, va_list ap) { int response; + bool rv = false; vfprintf(stderr, fmt, ap); - if(preset) + if (preset) fputs(" [Y/n] ", stderr); else fputs(" [y/N] ", stderr); - if ((response = fgetc(stdin)) != EOF) { - if (response == '\n') - return preset; - if (response == 'y' || response == 'Y') - return true; - if (response == 'n' || response == 'N') - return false; - } - return false; + response = fgetc(stdin); + if (response == '\n') + rv = preset; + else if (response == 'y' || response == 'Y') + rv = true; + else if (response == 'n' || response == 'N') + rv = false; + + /* read the rest of the line */ + while (response != EOF && response != '\n') + response = fgetc(stdin); + + return rv; } bool