From: Urban Wallasch Date: Wed, 19 May 2021 16:40:28 +0000 (+0200) Subject: * Added ETA information to kaoupload progress display. X-Git-Url: https://git.packet-gain.de/?a=commitdiff_plain;h=8700ecaf3aa7fc2440df5e0405459a08b9ec7d4d;p=kaotools.git * Added ETA information to kaoupload progress display. --- diff --git a/kaoupload.c b/kaoupload.c index e510bab..8e24433 100644 --- a/kaoupload.c +++ b/kaoupload.c @@ -103,6 +103,18 @@ static curl_off_t str_to_bwl( const char *s ) { return byps; } +static const char *eta_fmt(int s) { + static char tbuf[10]; + int h, m, n = 0; + h = s / 3600; + m = (s / 60) % 60; + s = s % 60; + if ( h ) + n = snprintf(tbuf, sizeof tbuf, "%02d:", h); + snprintf(tbuf + n, sizeof tbuf - n, "%02d:%02d", m, s); + return tbuf; +} + static uint64_t time_ms( void ) { struct timespec tv; clock_gettime( CLOCK_REALTIME, &tv ); @@ -326,6 +338,7 @@ static int upload_file( const char *fn ) { starttime = time_ms(); while ( fi.remn ) { + int eta; if ( gotsig ) { res = -1; break; @@ -337,6 +350,8 @@ static int upload_file( const char *fn ) { if ( CSIZE_HARDLIMIT < csize ) csize = CSIZE_HARDLIMIT; fprintf( stderr, "\r%3.f%% (%5.1f KiB/s) ", (double)fi.coff * 100 / fi.size, (double)fi.speed / 1024 ); + eta = (double)fi.remn / (fi.speed ? fi.speed : 1); + fprintf( stderr, " ETA: %s ", eta_fmt(eta)); // fprintf( stderr, "[csize: %ld] {offset: %ld} ", (long)csize, (long)fi.coff ); fflush( stderr ); }