From fa90e16b7d97621b55c84e4203a37877b598876f Mon Sep 17 00:00:00 2001 From: mharo Date: Sun, 28 Nov 1999 09:34:21 +0000 Subject: brucify Reviewed by: obrien --- bin/cp/cp.1 | 4 ++++ bin/cp/cp.c | 32 ++++++++++++++++---------------- bin/rm/rm.c | 26 +++++++++++++------------- 3 files changed, 33 insertions(+), 29 deletions(-) (limited to 'bin') diff --git a/bin/cp/cp.1 b/bin/cp/cp.1 index f51a28e..54e050a 100644 --- a/bin/cp/cp.1 +++ b/bin/cp/cp.1 @@ -214,6 +214,10 @@ option. This implementation supports that option, however, its use is strongly discouraged, as it does not correctly copy special files, symbolic links or fifo's. +.Pp +The +.Fl v +option is non-standard and its use in scripts is not recommended. .Sh SEE ALSO .Xr mv 1 , .Xr rcp 1 , diff --git a/bin/cp/cp.c b/bin/cp/cp.c index 9b5c05f..e528aea 100644 --- a/bin/cp/cp.c +++ b/bin/cp/cp.c @@ -253,23 +253,23 @@ copy(argv, type, fts_options) struct stat to_stat; FTS *ftsp; FTSENT *curr; - int base = 0, dne, nlen, rval; + int base = 0, dne, badcp, nlen, rval; char *p, *target_mid; if ((ftsp = fts_open(argv, fts_options, mastercmp)) == NULL) err(1, NULL); - for (rval = 0; (curr = fts_read(ftsp)) != NULL;) { + for (badcp = rval = 0; (curr = fts_read(ftsp)) != NULL; badcp = 0) { switch (curr->fts_info) { case FTS_NS: case FTS_DNR: case FTS_ERR: warnx("%s: %s", curr->fts_path, strerror(curr->fts_errno)); - rval = 1; + badcp = rval = 1; continue; case FTS_DC: /* Warn, continue. */ warnx("%s: directory causes a cycle", curr->fts_path); - rval = 1; + badcp = rval = 1; continue; case FTS_DP: /* Ignore, continue. */ continue; @@ -321,7 +321,7 @@ copy(argv, type, fts_options) if (target_mid - to.p_path + nlen > MAXPATHLEN) { warnx("%s%s: name too long (not copied)", to.p_path, p); - rval = 1; + badcp = rval = 1; continue; } (void)strncat(target_mid, p, nlen); @@ -338,7 +338,7 @@ copy(argv, type, fts_options) to_stat.st_ino == curr->fts_statp->st_ino) { warnx("%s and %s are identical (not copied).", to.p_path, curr->fts_path); - rval = 1; + badcp = rval = 1; if (S_ISDIR(curr->fts_statp->st_mode)) (void)fts_set(ftsp, curr, FTS_SKIP); continue; @@ -347,7 +347,7 @@ copy(argv, type, fts_options) S_ISDIR(to_stat.st_mode)) { warnx("cannot overwrite directory %s with non-directory %s", to.p_path, curr->fts_path); - rval = 1; + badcp = rval = 1; continue; } dne = 0; @@ -356,14 +356,14 @@ copy(argv, type, fts_options) switch (curr->fts_statp->st_mode & S_IFMT) { case S_IFLNK: if (copy_link(curr, !dne)) - rval = 1; + badcp = rval = 1; break; case S_IFDIR: if (!Rflag && !rflag) { warnx("%s is a directory (not copied).", curr->fts_path); (void)fts_set(ftsp, curr, FTS_SKIP); - rval = 1; + badcp = rval = 1; break; } /* @@ -389,7 +389,7 @@ copy(argv, type, fts_options) * forever. */ if (pflag && setfile(curr->fts_statp, 0)) - rval = 1; + badcp = rval = 1; else if (dne) (void)chmod(to.p_path, curr->fts_statp->st_mode); @@ -398,27 +398,27 @@ copy(argv, type, fts_options) case S_IFCHR: if (Rflag) { if (copy_special(curr->fts_statp, !dne)) - rval = 1; + badcp = rval = 1; } else { if (copy_file(curr, dne)) - rval = 1; + badcp = rval = 1; } break; case S_IFIFO: if (Rflag) { if (copy_fifo(curr->fts_statp, !dne)) - rval = 1; + badcp = rval = 1; } else { if (copy_file(curr, dne)) - rval = 1; + badcp = rval = 1; } break; default: if (copy_file(curr, dne)) - rval = 1; + badcp = rval = 1; break; } - if (!rval && vflag) + if (vflag && !badcp) (void)printf("%s -> %s\n", curr->fts_path, to.p_path); } if (errno) diff --git a/bin/rm/rm.c b/bin/rm/rm.c index c12872b..7d7de4b 100644 --- a/bin/rm/rm.c +++ b/bin/rm/rm.c @@ -150,7 +150,6 @@ rm_tree(argv) int needstat; int flags; int rval; - int e; /* * Remove a file hierarchy. If forcing removal (-f), or interactive @@ -226,7 +225,7 @@ rm_tree(argv) !(p->fts_statp->st_flags & (SF_APPEND|SF_IMMUTABLE))) rval = chflags(p->fts_accpath, p->fts_statp->st_flags &= ~(UF_APPEND|UF_IMMUTABLE)); - if (!rval) { + if (rval == 0) { /* * If we can't read or search the directory, may still be * able to remove it. Don't print out the un{read,search}able @@ -235,9 +234,9 @@ rm_tree(argv) switch (p->fts_info) { case FTS_DP: case FTS_DNR: - e = rmdir(p->fts_accpath); - if (e == 0 || (fflag && errno == ENOENT)) { - if (e == 0 && vflag) + rval = rmdir(p->fts_accpath); + if (rval == 0 || (fflag && errno == ENOENT)) { + if (rval == 0 && vflag) (void)printf("%s\n", p->fts_accpath); continue; @@ -245,9 +244,9 @@ rm_tree(argv) break; case FTS_W: - e = undelete(p->fts_accpath); - if (e == 0 || (fflag && errno == ENOENT)) { - if (e == 0 && vflag) + rval = undelete(p->fts_accpath); + if (rval == 0 && (fflag && errno == ENOENT)) { + if (vflag) (void)printf("%s\n", p->fts_accpath); continue; @@ -257,9 +256,9 @@ rm_tree(argv) default: if (Pflag) rm_overwrite(p->fts_accpath, NULL); - e = unlink(p->fts_accpath); - if (e == 0 || (fflag && errno == ENOENT)) { - if (e == 0 && vflag) + rval = unlink(p->fts_accpath); + if (rval == 0 || (fflag && errno == ENOENT)) { + if (rval == 0 && vflag) (void)printf("%s\n", p->fts_accpath); continue; @@ -316,7 +315,7 @@ rm_file(argv) (sb.st_flags & (UF_APPEND|UF_IMMUTABLE)) && !(sb.st_flags & (SF_APPEND|SF_IMMUTABLE))) rval = chflags(f, sb.st_flags & ~(UF_APPEND|UF_IMMUTABLE)); - if (!rval) { + if (rval == 0) { if (S_ISWHT(sb.st_mode)) rval = undelete(f); else if (S_ISDIR(sb.st_mode)) @@ -331,7 +330,7 @@ rm_file(argv) warn("%s", f); eval = 1; } - if (vflag) + if (vflag && rval == 0) (void)printf("%s\n", f); } } @@ -472,6 +471,7 @@ checkdot(argv) void usage() { + (void)fprintf(stderr, "usage: rm [-f | -i] [-dPRrvW] file ...\n"); exit(EX_USAGE); } -- cgit v1.1