diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2007-07-31 21:21:12 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2007-07-31 21:21:12 +0000 |
commit | 2d7aaaa5cb537cfccbdac8acde3b16f019f34148 (patch) | |
tree | 512c626a345c9caab9b32122c2d5281572be411c /usr.bin/cdio/rip.c | |
parent | 5be8c4b434e9adf32dd19a223ecc22db5c2a45e4 (diff) |
make rip code work like mmc code for how it does progress reports (use
a timer, so that stderr does not get splattered); tested by xsa and others
Diffstat (limited to 'usr.bin/cdio/rip.c')
-rw-r--r-- | usr.bin/cdio/rip.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/usr.bin/cdio/rip.c b/usr.bin/cdio/rip.c index db26a990e04..0d5997b4c94 100644 --- a/usr.bin/cdio/rip.c +++ b/usr.bin/cdio/rip.c @@ -1,3 +1,5 @@ +/* $OpenBSD: rip.c,v 1.6 2007/07/31 21:21:11 deraadt Exp $ */ + /* * Copyright (c) 2007 Alexey Vatchenko <av@bsdua.org> * @@ -356,6 +358,7 @@ read_data_sector(u_int32_t lba, u_char *sec, u_int32_t secsize) int read_track(int fd, struct track_info *ti) { + struct timeval tv, otv, atv; u_int32_t i, blksize, n_sec; u_char *sec; int error; @@ -366,9 +369,19 @@ read_track(int fd, struct track_info *ti) if (sec == NULL) return (-1); + timerclear(&otv); + atv.tv_sec = 1; + atv.tv_usec = 0; + for (i = 0; i < n_sec; ) { - fprintf(stderr, "track %u '%c' %08u/%08u %3u%%\r", ti->track, - (ti->isaudio) ? 'a' : 'd', i, n_sec, 100 * i / n_sec); + gettimeofday(&tv, NULL); + if (timercmp(&tv, &otv, >)) { + fprintf(stderr, "\rtrack %u '%c' %08u/%08u %3u%%", + ti->track, + (ti->isaudio) ? 'a' : 'd', i, n_sec, + 100 * i / n_sec); + timeradd(&tv, &atv, &otv); + } error = read_data_sector(i + ti->start_lba, sec, blksize); if (error == 0) { @@ -388,7 +401,8 @@ read_track(int fd, struct track_info *ti) } free(sec); - fprintf(stderr, "track %u '%c' %08u/%08u 100%%\n", ti->track, + fprintf(stderr, "\rtrack %u '%c' %08u/%08u 100%%\n", + ti->track, (ti->isaudio) ? 'a' : 'd', i, n_sec); return (0); } |