diff options
author | Brian Feldman <green@FreeBSD.org> | 1999-09-16 19:50:59 +0000 |
---|---|---|
committer | Brian Feldman <green@FreeBSD.org> | 1999-09-16 19:50:59 +0000 |
commit | 5ff6541e7a8bf367578694b461f3c49ee5ae8acb (patch) | |
tree | 1999ffb745326217871271b8c4cbe49acbc72aab | |
parent | 848f4ae4fb82dc273f7930fefc5edf8b8638ac52 (diff) | |
download | src-5ff6541e7a8bf367578694b461f3c49ee5ae8acb.tar.gz src-5ff6541e7a8bf367578694b461f3c49ee5ae8acb.zip |
Make count=0 set cpy_cnt to -1, which is slight overloading, but makes
what I was trying to do work much better (ie at all. I could have sworn
it was working...) Fix a SEEK_SET to be SEEK_CUR, and make Bruce's
lseek() test work correctly.
Notes
Notes:
svn path=/head/; revision=51335
-rw-r--r-- | bin/dd/args.c | 2 | ||||
-rw-r--r-- | bin/dd/dd.c | 19 | ||||
-rw-r--r-- | bin/dd/position.c | 2 |
3 files changed, 18 insertions, 5 deletions
diff --git a/bin/dd/args.c b/bin/dd/args.c index 734850307a02..c3c6d049d627 100644 --- a/bin/dd/args.c +++ b/bin/dd/args.c @@ -209,6 +209,8 @@ f_count(arg) cpy_cnt = get_num(arg); if (cpy_cnt < 0) errx(1, "count cannot be negative"); + if (cpy_cnt == 0) + cpy_cnt = -1; } static void diff --git a/bin/dd/dd.c b/bin/dd/dd.c index da70ca7375e9..49fd7be22f0b 100644 --- a/bin/dd/dd.c +++ b/bin/dd/dd.c @@ -225,10 +225,13 @@ getfdtype(io) if (S_ISCHR(sb.st_mode) && (type & D_TAPE) == 0) io->flags |= ISCHR; } - } else if (lseek(io->fd, (off_t)0, SEEK_CUR) == 0) - io->flags |= ISSEEK; - else if (errno == ESPIPE) + return; + } + errno = 0; + if (lseek(io->fd, (off_t)0, SEEK_CUR) == -1 && errno == ESPIPE) io->flags |= ISPIPE; + else + io->flags |= ISSEEK; } static void @@ -237,8 +240,16 @@ dd_in() ssize_t n; for (;;) { - if (cpy_cnt && (st.in_full + st.in_part) >= cpy_cnt) + switch (cpy_cnt) { + case -1: /* count=0 was specified */ return; + case 0: + break; + default: + if (st.in_full + st.in_part >= cpy_cnt) + return; + break; + } /* * Zero the buffer first if sync; if doing block operations, diff --git a/bin/dd/position.c b/bin/dd/position.c index e6774a53e4fc..9d3d0d896b65 100644 --- a/bin/dd/position.c +++ b/bin/dd/position.c @@ -132,7 +132,7 @@ pos_out() */ if (!(out.flags & ISTAPE)) { errno = 0; - if (lseek(out.fd, out.offset * out.dbsz, SEEK_SET) == -1 && + if (lseek(out.fd, out.offset * out.dbsz, SEEK_CUR) == -1 && errno != 0) err(1, "%s", out.name); return; |