FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 03-18-2011, 02:03 PM
Dave Reisner
 
Default pacman/util: flush terminal input before reading response

Addresses FS#20538

Signed-off-by: Dave Reisner <d@falconindy.com>
---
src/pacman/util.c | 17 +++++++++++++++++
src/pacman/util.h | 1 +
2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/src/pacman/util.c b/src/pacman/util.c
index 558d6f8..7fb4562 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -37,6 +37,7 @@
#include <unistd.h>
#include <limits.h>
#include <wchar.h>
+#include <termios.h> /* tcflush */

#include <alpm.h>
#include <alpm_list.h>
@@ -100,6 +101,16 @@ int needs_root(void)
}
}

+/* discard unhandled input on the terminal's input buffer */
+int flush_term_input(void) {
+ if(isatty(fileno(stdin))) {
+ return(tcflush(fileno(stdin), TCIFLUSH));
+ }
+
+ /* fail silently */
+ return(0);
+}
+
/* gets the current screen column width */
int getcols(void)
{
@@ -812,6 +823,8 @@ int multiselect_question(char *array, int count)
break;
}

+ flush_term_input();
+
if(fgets(response, sizeof(response), stdin)) {
strtrim(response);
if(strlen(response) > 0) {
@@ -849,6 +862,8 @@ int select_question(int count)
break;
}

+ flush_term_input();
+
if(fgets(response, sizeof(response), stdin)) {
strtrim(response);
if(strlen(response) > 0) {
@@ -891,6 +906,8 @@ static int question(short preset, char *fmt, va_list args)
return preset;
}

+ flush_term_input();
+
if(fgets(response, sizeof(response), stdin)) {
strtrim(response);
if(strlen(response) == 0) {
diff --git a/src/pacman/util.h b/src/pacman/util.h
index 234a631..27cbf46 100644
--- a/src/pacman/util.h
+++ b/src/pacman/util.h
@@ -59,6 +59,7 @@ int str_cmp(const void *s1, const void *s2);
void display_new_optdepends(pmpkg_t *oldpkg, pmpkg_t *newpkg);
void display_optdepends(pmpkg_t *pkg);
void print_packages(const alpm_list_t *packages);
+int flush_term_input(void);
void select_display(const alpm_list_t *pkglist);
int select_question(int count);
int multiselect_question(char *array, int count);
--
1.7.4.1


--/e2eDi0V/xtL+Mc8
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline



--/e2eDi0V/xtL+Mc8--
 

Thread Tools




All times are GMT. The time now is 03:57 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org