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 2019-05-02 20:15:09 +03:00 committed by Duncan Overbruck
parent cfc8e0a580
commit 56aa77d51b

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