mirror of
https://github.com/upa/mscp.git
synced 2026-02-15 09:44:43 +08:00
wrap print progress in pprint
This commit is contained in:
32
src/pprint.c
Normal file
32
src/pprint.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <pthread.h>
|
||||
|
||||
static int pprint_level = 1;
|
||||
/* level 1: print progress bar only.
|
||||
* level 2: print copy start/done messages.
|
||||
* level 3: print ssh connection establishment/disconnection.
|
||||
* level 4: print chunk information.
|
||||
*/
|
||||
|
||||
static pthread_mutex_t pprint_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
void pprint_set_level(int level)
|
||||
{
|
||||
pprint_level = level;
|
||||
}
|
||||
|
||||
void pprint(int level, const char *fmt, ...)
|
||||
{
|
||||
va_list va;
|
||||
|
||||
if (level <= pprint_level) {
|
||||
pthread_mutex_lock(&pprint_lock);
|
||||
va_start(va, fmt);
|
||||
vfprintf(stdout, fmt, va);
|
||||
fflush(stdout);
|
||||
va_end(va);
|
||||
pthread_mutex_unlock(&pprint_lock);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user