diff options
author | sos <sos@FreeBSD.org> | 2000-03-02 21:49:10 +0000 |
---|---|---|
committer | sos <sos@FreeBSD.org> | 2000-03-02 21:49:10 +0000 |
commit | 2809faac72adeae047da4c05cc78cca99948ee40 (patch) | |
tree | a763009e0e92d3d70c5206d40441a95a535ce4e9 /usr.sbin/burncd | |
parent | 2db9bc08ef2e9b58d9f8e9dee47e1b6a501dd45e (diff) | |
download | FreeBSD-src-2809faac72adeae047da4c05cc78cca99948ee40.zip FreeBSD-src-2809faac72adeae047da4c05cc78cca99948ee40.tar.gz |
Add a percentage-meter to the progress report.
Submitted by: peter
Diffstat (limited to 'usr.sbin/burncd')
-rw-r--r-- | usr.sbin/burncd/burncd.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/usr.sbin/burncd/burncd.c b/usr.sbin/burncd/burncd.c index 0f5e154..ea36208 100644 --- a/usr.sbin/burncd/burncd.c +++ b/usr.sbin/burncd/burncd.c @@ -51,9 +51,10 @@ main(int argc, char **argv) int ch, speed = 1, preemp = 0, test_write = 0, eject = 0, quiet = 0; char *devname = "/dev/acd0c"; char buf[2352*BLOCKS]; - int arg, file, addr, count; + int arg, file, addr, count, filesize; int block_size = 0, cdopen = 0, size, tot_size = 0; struct cdr_track track; + struct stat stat; while ((ch = getopt(argc, argv, "ef:pqs:t")) != -1) { switch (ch) { @@ -159,17 +160,18 @@ main(int argc, char **argv) if (ioctl(fd, CDRIOCNEXTWRITEABLEADDR, &addr) < 0) err(EX_IOERR, "ioctl(CDRIOCNEXTWRITEABLEADDR)"); + if (fstat(file, &stat) < 0) + err(EX_IOERR, "fstat(%s)", argv[arg]); + filesize = stat.st_size / 1024; if (!quiet) { - struct stat stat; - - if (fstat(file, &stat) < 0) - err(EX_IOERR, "fstat(%s)", argv[arg]); fprintf(stderr, "next writeable LBA %d\n", addr); - fprintf(stderr, "writing from file %s size %qd KB\n", - argv[arg], stat.st_size / 1024); + fprintf(stderr, "writing from file %s size %d KB\n", + argv[arg], filesize); } lseek(fd, addr * block_size, SEEK_SET); size = 0; + if (filesize == 0) + filesize++; /* cheat, avoid divide by zero */ while ((count = read(file, buf, block_size * BLOCKS)) > 0) { int res; @@ -186,10 +188,14 @@ main(int argc, char **argv) } size += count; tot_size += count; - if (!quiet) + if (!quiet) { + int pct; + + pct = (size / 1024) * 100 / filesize; fprintf(stderr, "written this track %d KB" - " total %d KB\r", - size/1024, tot_size/1024); + " (%d%%) total %d KB\r", + size/1024, pct, tot_size/1024); + } } if (!quiet) fprintf(stderr, "\n"); |