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)
This commit is contained in:
human authored and Duncan Overbruck committed 2019-06-07 19:38:51 +02:00
1 parent cfc8e0a580
commit 56aa77d51b
1 file changed
+15 -10
+15 -10
View File
@@ -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