From 32f2e5330400925d52531180ee72a8c2b2c468f8 Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Fri, 10 Aug 2012 14:47:31 +0200 Subject: printf-utils: Added function printf_and_wait --- src/printf-utils.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/printf-utils.c') diff --git a/src/printf-utils.c b/src/printf-utils.c index 8907dba..7eacb0a 100644 --- a/src/printf-utils.c +++ b/src/printf-utils.c @@ -19,6 +19,8 @@ #include #include +#include +#include #include "printf-utils.h" @@ -57,3 +59,35 @@ void printf_progressbar(unsigned long long part, unsigned long long total) { #endif } + +void printf_and_wait(const char * format, ...) { + + va_list ap; + char c; + fd_set rfds; + struct timeval tv; + + tv.tv_sec = 0; + tv.tv_usec = 0; + + FD_ZERO(&rfds); + FD_SET(0, &rfds); + + while ( select(1, &rfds, NULL, NULL, &tv) == 1 ) + read(0, &c, 1); + + va_start(ap, format); + vprintf(format, ap); + va_end(ap); + fflush(stdout); + + FD_ZERO(&rfds); + FD_SET(0, &rfds); + + while ( select(1, &rfds, NULL, NULL, NULL) == 1 ) { + read(0, &c, 1); + if ( c == '\n' ) + break; + } + +} -- cgit v1.2.3