summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main2.c4
-rw-r--r--src/printf-utils.c34
-rw-r--r--src/printf-utils.h1
3 files changed, 36 insertions, 3 deletions
diff --git a/src/main2.c b/src/main2.c
index 2736828..b18b1ee 100644
--- a/src/main2.c
+++ b/src/main2.c
@@ -721,9 +721,7 @@ int main(int argc, char **argv) {
if ( usb_dev->flash_device->protocol != FLASH_COLD ) {
usb_close_device(usb_dev);
- printf("Unplug USB cable, turn device off, press ENTER and plug USB cable again\n");
- fflush(stdin);
- getchar();
+ printf_and_wait("Unplug USB cable, turn device off, press ENTER and plug USB cable again");
continue;
}
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;
+ }
+
+}
diff --git a/src/printf-utils.h b/src/printf-utils.h
index 5691987..f475214 100644
--- a/src/printf-utils.h
+++ b/src/printf-utils.h
@@ -29,5 +29,6 @@ extern int printf_prev;
#define PRINTF_ERROR(...) do { PRINTF_END(); ERROR_INFO(__VA_ARGS__); } while (0)
void printf_progressbar(unsigned long long part, unsigned long long total);
+void printf_and_wait(const char * format, ...);
#endif