summaryrefslogtreecommitdiffstats
path: root/src/printf-utils.c
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2012-08-10 14:47:31 +0200
committerPali Rohár <pali.rohar@gmail.com>2012-08-10 14:47:31 +0200
commit32f2e5330400925d52531180ee72a8c2b2c468f8 (patch)
treedc9b295fc8ad63d2531668f752b17bfd8efa9be3 /src/printf-utils.c
parentf79b653523980cb3a7510a474860aa1594868c9f (diff)
download0xFFFF-32f2e5330400925d52531180ee72a8c2b2c468f8.tar.bz2
printf-utils: Added function printf_and_wait
Diffstat (limited to 'src/printf-utils.c')
-rw-r--r--src/printf-utils.c34
1 files changed, 34 insertions, 0 deletions
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 <stdio.h>
#include <stdlib.h>
+#include <stdarg.h>
+#include <unistd.h>
#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;
+ }
+
+}