Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDave Reisner <d@falconindy.com>2011-03-18 11:03:28 -0400
committerDan McGee <dan@archlinux.org>2011-08-09 18:59:49 -0500
commit6b57118c15c6ba60fd84e72ab1ec32bad7f7f7de (patch)
tree82c781e3cfbda411a2759375bab5b93139aeb78a /src
parent07996bfac7cf172e656f7527794512fd596a9edf (diff)
pacman/util: flush terminal input before reading response
Addresses FS#20538 Conflicts: src/pacman/util.c Signed-off-by: Dave Reisner <d@falconindy.com> Signed-off-by: Dan McGee <dan@archlinux.org> (cherry picked from commit 9477abc3591905a20acbfe7b8ce7832617d72701)
Diffstat (limited to 'src')
-rw-r--r--src/pacman/util.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 53dbd637..0cb6a9f4 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -37,6 +37,9 @@
#include <unistd.h>
#include <limits.h>
#include <wchar.h>
+#ifdef HAVE_TERMIOS_H
+#include <termios.h> /* tcflush */
+#endif
#include <alpm.h>
#include <alpm_list.h>
@@ -100,6 +103,18 @@ int needs_root(void)
}
}
+/* discard unhandled input on the terminal's input buffer */
+static int flush_term_input(void) {
+#ifdef HAVE_TCFLUSH
+ if(isatty(fileno(stdin))) {
+ return(tcflush(fileno(stdin), TCIFLUSH));
+ }
+#endif
+
+ /* fail silently */
+ return 0;
+}
+
/* gets the current screen column width */
int getcols(int def)
{
@@ -828,6 +843,8 @@ int multiselect_question(char *array, int count)
break;
}
+ flush_term_input();
+
if(fgets(response, response_len, stdin)) {
const size_t response_incr = 64;
/* handle buffer not being large enough to read full line case */
@@ -887,6 +904,8 @@ int select_question(int count)
break;
}
+ flush_term_input();
+
if(fgets(response, sizeof(response), stdin)) {
strtrim(response);
if(strlen(response) > 0) {
@@ -934,6 +953,8 @@ static int question(short preset, char *fmt, va_list args)
}
fflush(stream);
+ flush_term_input();
+
if(fgets(response, sizeof(response), stdin)) {
strtrim(response);
if(strlen(response) == 0) {