Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
if (pakfire_has_flag(pakfire, PAKFIRE_FLAGS_NON_INTERACTIVE))
return 0;
+ char* line = NULL;
+ size_t length = 0;
+ int r = 1;
+
while (1) {
// Print question
printf("%s ", question);
// Wait for user to enter something
- char p = getchar();
+ ssize_t bytes_read = getline(&line, &length, stdin);
+ if (bytes_read < 0)
+ goto END;
- switch (p) {
+ // Must have one character and newline
+ if (!line || strlen(line) != 2)
+ continue;
+
+ switch (*line) {
// Positive response
case 'Y':
case 'y':
- return 0;
+ r = 0;
+ goto END;
// Negative response
- case EOF:
case 'N':
case 'n':
- return 1;
+ r = 1;
+ goto END;
// Unknown input, repeat
default:
}
}
- return 1;
+END:
+ if (line)
+ free(line);
+
+ return r;
}
static int pakfire_ui_enter_number(Pakfire pakfire, const char* question,