#include <time.h>
#include <stdio.h>
#include <signal.h>

char buffer[8192];

static long int now,prev,t0;
static long long int total=0, lastb=0;

void sig(int signum) {
   long int t = now-t0;
   now=time(NULL);
   fprintf(stderr,"\r%lld octets en %d:%02d:%02d = %lld ko/s (%lld ko/s avg)       \r",total,
                  t/3600,(t%3600)/60,t%60, ((total-lastb)/((now-prev)?:1))>>10, (total/(t?:1))>>10);
   prev=now;  
   lastb=total;
   signal(signum, sig);
   alarm(1);
}

main() {
   int c;
   long int l;

   t0=time(NULL);

   signal(SIGALRM, sig);
   alarm(1);

   while ((l=read(0,buffer,sizeof(buffer))) >0) {
        total += l;
   }
   fprintf(stderr,"\n");
   exit(0);
}
