printf-utils: Added function printf_and_wait

This commit is contained in:
Pali Rohár committed 2012-08-10 14:47:31 +02:00
1 parent f79b653523
commit 32f2e53304
3 files changed
+36 -3

No files matched your search

+34
View File
@@ -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;
}
}