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,6 +41,7 @@ static bool
question(bool preset, const char *fmt, va_list ap) question(bool preset, const char *fmt, va_list ap)
{ {
int response; int response;
bool rv = false;
vfprintf(stderr, fmt, ap); vfprintf(stderr, fmt, ap);
if (preset) if (preset)
@ -48,15 +49,19 @@ question(bool preset, const char *fmt, va_list ap)
else else
fputs(" [y/N] ", stderr); fputs(" [y/N] ", stderr);
if ((response = fgetc(stdin)) != EOF) { response = fgetc(stdin);
if (response == '\n') if (response == '\n')
return preset; rv = preset;
if (response == 'y' || response == 'Y') else if (response == 'y' || response == 'Y')
return true; rv = true;
if (response == 'n' || response == 'N') else if (response == 'n' || response == 'N')
return false; rv = false;
}
return false; /* read the rest of the line */
while (response != EOF && response != '\n')
response = fgetc(stdin);
return rv;
} }
bool bool