X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/0f00dc4c8eb47e67bc0f148c2dd109f73a451e0a..bd6d65e32b835551677456bf286d09ced6859882:/progs/cc-progress.c diff --git a/progs/cc-progress.c b/progs/cc-progress.c index 903e80e6..055556c3 100644 --- a/progs/cc-progress.c +++ b/progs/cc-progress.c @@ -31,6 +31,8 @@ #include "config.h" +#include + #include "cc.h" #ifndef PATHSEP @@ -129,16 +131,15 @@ static void prhuman_data(FILE *fp, off_t n) int fprogress_init(fprogress *f, const char *name, FILE *fp) { const char *p; + struct stat st; off_t o, sz = -1; size_t n; /* --- Set up the offset --- */ - if ((o = ftello(fp)) >= 0 && - fseeko(fp, 0, SEEK_END) >= 0 && - (sz = ftello(fp), - fseeko(fp, o, SEEK_SET) < 0)) - return (-1); + o = lseek(fileno(fp), 0, SEEK_CUR); + if (fstat(fileno(fp), &st)) return (-1); + sz = (S_ISREG(st.st_mode)) ? st.st_size : -1; if (o != -1 && sz != -1) sz -= o; f->o = f->olast = 0; f->sz = sz; @@ -177,7 +178,8 @@ int fprogress_init(fprogress *f, const char *name, FILE *fp) void fprogress_clear(fprogress *f) { fprintf(stderr, "\r%*s\r", - sizeof(f->name) + 2*PRHUMAN_DATAWD + PRHUMAN_TIMEWD + BARWD + 16, + (int)(sizeof(f->name) + 2*PRHUMAN_DATAWD + + PRHUMAN_TIMEWD + BARWD + 16), ""); }