summaryrefslogtreecommitdiffstats
path: root/bin/dd/position.c
diff options
context:
space:
mode:
authorgreen <green@FreeBSD.org>1999-09-11 00:02:42 +0000
committergreen <green@FreeBSD.org>1999-09-11 00:02:42 +0000
commita9f7b5ee698afe56d1167bfa395f23b1fff1730c (patch)
tree393cf880a9dcff3b4a3f9f87e347a3aae411d2dd /bin/dd/position.c
parentf95e7771eeb859d148e01daa24d5fa2368720e47 (diff)
downloadFreeBSD-src-a9f7b5ee698afe56d1167bfa395f23b1fff1730c.zip
FreeBSD-src-a9f7b5ee698afe56d1167bfa395f23b1fff1730c.tar.gz
Make a bit more headway with dd's argument parsing, etc. get_bsz() is
renamed get_num() since it's not just about block sizes. skip and seek can be any offset, including negative, now. Some style bogons are fixed.
Diffstat (limited to 'bin/dd/position.c')
-rw-r--r--bin/dd/position.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/bin/dd/position.c b/bin/dd/position.c
index 5299c5b..74b612c 100644
--- a/bin/dd/position.c
+++ b/bin/dd/position.c
@@ -47,6 +47,7 @@ static const char rcsid[] =
#include <sys/mtio.h>
#include <err.h>
+#include <errno.h>
#include <unistd.h>
#include "dd.h"
@@ -67,7 +68,8 @@ pos_in()
/* If not a character, pipe or tape device, try to seek on it. */
if (!(in.flags & (ISCHR|ISPIPE|ISTAPE)) || in.flags & ISDISK) {
- if (lseek(in.fd, in.offset * in.dbsz, SEEK_CUR) == -1)
+ errno = 0;
+ if (lseek(in.fd, in.offset * in.dbsz, SEEK_CUR) == -1 && errno)
err(1, "%s", in.name);
return;
}
@@ -77,6 +79,8 @@ pos_in()
* being skipped. No differentiation for reading complete and partial
* blocks for other devices.
*/
+ if (in.offset < 0)
+ errx(1, "skip must be positive");
for (bcnt = in.dbsz, cnt = in.offset, warned = 0; cnt;) {
if ((nr = read(in.fd, in.db, bcnt)) > 0) {
if (in.flags & ISPIPE) {
@@ -123,7 +127,9 @@ pos_out()
/* If not a character, pipe or tape device, try to seek on it. */
if (!(out.flags & (ISCHR|ISPIPE|ISTAPE)) || out.flags & ISDISK) {
- if (lseek(out.fd, out.offset * out.dbsz, SEEK_SET) == -1)
+ errno = 0;
+ if (lseek(out.fd, out.offset * out.dbsz, SEEK_SET) == -1 &&
+ errno)
err(1, "%s", out.name);
return;
}
@@ -139,6 +145,8 @@ pos_out()
}
/* Read it. */
+ if (out.offset < 0)
+ errx(1, "seek must be positive");
for (cnt = 0; cnt < out.offset; ++cnt) {
if ((n = read(out.fd, out.db, out.dbsz)) > 0)
continue;
OpenPOWER on IntegriCloud