summaryrefslogtreecommitdiffstats
path: root/bin/dd/position.c
diff options
context:
space:
mode:
authorgreen <green@FreeBSD.org>1999-09-12 16:51:53 +0000
committergreen <green@FreeBSD.org>1999-09-12 16:51:53 +0000
commit4c16a85a3ff03636818f24c79ff2bc5947df9263 (patch)
tree27ec4fb5de7c3368adcff8f419831e3fad5929a9 /bin/dd/position.c
parent24f1ee63f7883c5a3b659be2be4b666369e6142d (diff)
downloadFreeBSD-src-4c16a85a3ff03636818f24c79ff2bc5947df9263.zip
FreeBSD-src-4c16a85a3ff03636818f24c79ff2bc5947df9263.tar.gz
Even more cleanups to dd(1). This is probably the culmination of the
BDEification process of dd(1). Most of the changes are from BDE's archive. Support for negative offsets is gone again, but the case where you lseek() onto byte -1 of something from a negative offset using seek/skip is fixed; if you end up on -1, you won't get a false positive lseek failure. The biggest changes are to data types (more size_t, for instance) and argument parsing. skip/seek on /dev/{,k}mem now occurs (instead of "read until you reach the offset") due to mem devices now being D_DISK. Some const things are now correctly declared as such, and the "case table" building is better. The only thing that seems to be left to make dd(1) everything TOG wants it to be is l10n.
Diffstat (limited to 'bin/dd/position.c')
-rw-r--r--bin/dd/position.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/bin/dd/position.c b/bin/dd/position.c
index 74b612c..6c0f684 100644
--- a/bin/dd/position.c
+++ b/bin/dd/position.c
@@ -62,14 +62,16 @@ static const char rcsid[] =
void
pos_in()
{
- int bcnt, warned;
- ssize_t nr;
off_t cnt;
+ int warned;
+ ssize_t nr;
+ size_t bcnt;
/* If not a character, pipe or tape device, try to seek on it. */
if (!(in.flags & (ISCHR|ISPIPE|ISTAPE)) || in.flags & ISDISK) {
errno = 0;
- if (lseek(in.fd, in.offset * in.dbsz, SEEK_CUR) == -1 && errno)
+ if (lseek(in.fd, in.offset * in.dbsz, SEEK_CUR) == -1 &&
+ errno != 0)
err(1, "%s", in.name);
return;
}
@@ -79,8 +81,6 @@ 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) {
@@ -129,7 +129,7 @@ pos_out()
if (!(out.flags & (ISCHR|ISPIPE|ISTAPE)) || out.flags & ISDISK) {
errno = 0;
if (lseek(out.fd, out.offset * out.dbsz, SEEK_SET) == -1 &&
- errno)
+ errno != 0)
err(1, "%s", out.name);
return;
}
@@ -145,8 +145,6 @@ 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