cp(1)/mv(1): Bring back a number of cleanups we did previously.
authorSascha Wildner <saw@online.de>
Fri, 16 Nov 2012 12:19:38 +0000 (13:19 +0100)
committerSascha Wildner <saw@online.de>
Fri, 16 Nov 2012 12:19:38 +0000 (13:19 +0100)
People (including myself) have put their time and thought into
this in the past, so we don't want this simply papered over with
the previous state.

bin/cp/cp.c
bin/cp/utils.c
bin/mv/mv.c

index 86d8ae3..a9e144e 100644 (file)
@@ -165,7 +165,7 @@ main(int argc, char *argv[])
                fts_options &= ~FTS_PHYSICAL;
                fts_options |= FTS_LOGICAL | FTS_COMFOLLOW;
        }
-       (void)signal(SIGINFO, siginfo);
+       signal(SIGINFO, siginfo);
 
        /* Save the target base in "to". */
        target = argv[--argc];
@@ -330,7 +330,7 @@ copy(char *argv[], enum op type, int fts_options)
                                rval = 1;
                                continue;
                        }
-                       (void)strncat(target_mid, p, nlen);
+                       strncat(target_mid, p, nlen);
                        to.p_end = target_mid + nlen;
                        *to.p_end = 0;
                        STRIP_TRAILING_SLASH(to);
@@ -378,7 +378,7 @@ copy(char *argv[], enum op type, int fts_options)
                                    to.p_path, curr->fts_path);
                                rval = 1;
                                if (S_ISDIR(curr->fts_statp->st_mode))
-                                       (void)fts_set(ftsp, curr, FTS_SKIP);
+                                       fts_set(ftsp, curr, FTS_SKIP);
                                continue;
                        }
                        if (!S_ISDIR(curr->fts_statp->st_mode) &&
@@ -409,7 +409,7 @@ copy(char *argv[], enum op type, int fts_options)
                        if (!Rflag) {
                                warnx("%s is a directory (not copied).",
                                    curr->fts_path);
-                               (void)fts_set(ftsp, curr, FTS_SKIP);
+                               fts_set(ftsp, curr, FTS_SKIP);
                                badcp = rval = 1;
                                break;
                        }
@@ -465,7 +465,7 @@ copy(char *argv[], enum op type, int fts_options)
                        break;
                }
                if (vflag && !badcp)
-                       (void)printf("%s -> %s\n", curr->fts_path, to.p_path);
+                       printf("%s -> %s\n", curr->fts_path, to.p_path);
        }
        if (errno)
                err(1, "fts_read");
index 55356fb..23cc7b0 100644 (file)
@@ -83,17 +83,17 @@ copy_file(const FTSENT *entp, int dne)
                if (nflag) {
                        if (vflag)
                                printf("%s not overwritten\n", to.p_path);
-                       (void)close(from_fd);
+                       close(from_fd);
                        return (0);
                } else if (iflag) {
-                       (void)fprintf(stderr, "overwrite %s? %s",
+                       fprintf(stderr, "overwrite %s? %s",
                                        to.p_path, YESNO);
                        checkch = ch = getchar();
                        while (ch != '\n' && ch != EOF)
                                ch = getchar();
                        if (checkch != 'y' && checkch != 'Y') {
-                               (void)close(from_fd);
-                               (void)fprintf(stderr, "not overwritten\n");
+                               close(from_fd);
+                               fprintf(stderr, "not overwritten\n");
                                return (1);
                        }
                }
@@ -101,7 +101,7 @@ copy_file(const FTSENT *entp, int dne)
                if (fflag) {
                    /* remove existing destination file name, 
                     * create a new file  */
-                   (void)unlink(to.p_path);
+                   unlink(to.p_path);
                    if (!lflag)
                        to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT,
                            fs->st_mode & ~(S_ISUID | S_ISGID));
@@ -118,7 +118,7 @@ copy_file(const FTSENT *entp, int dne)
 
        if (to_fd == -1) {
                warn("%s", to.p_path);
-               (void)close(from_fd);
+               close(from_fd);
                return (1);
        }
 
@@ -146,7 +146,7 @@ copy_file(const FTSENT *entp, int dne)
                                wtotal += wcount;
                                if (info) {
                                        info = 0;
-                                       (void)fprintf(stderr,
+                                       fprintf(stderr,
                                            "%s -> %s %3d%%\n",
                                            entp->fts_path, to.p_path,
                                            cp_pct(wtotal, fs->st_size));
@@ -176,7 +176,7 @@ copy_file(const FTSENT *entp, int dne)
                                        wtotal += wcount;
                                        if (info) {
                                                info = 0;
-                                               (void)fprintf(stderr,
+                                               fprintf(stderr,
                                                    "%s -> %s %3d%%\n",
                                                    entp->fts_path, to.p_path,
                                                    cp_pct(wtotal, fs->st_size));
@@ -218,7 +218,7 @@ copy_file(const FTSENT *entp, int dne)
                }
        }
 
-       (void)close(from_fd);
+       close(from_fd);
 
        return (rval);
 }
@@ -341,7 +341,7 @@ void
 usage(void)
 {
 
-       (void)fprintf(stderr, "%s\n%s\n",
+       fprintf(stderr, "%s\n%s\n",
 "usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpvx] source_file target_file",
 "       cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpvx] source_file ... "
 "target_directory");
index 6e09b4d..cc68878 100644 (file)
@@ -131,7 +131,7 @@ main(int argc, char *argv[])
        /* It's a directory, move each file into it. */
        if (strlen(argv[argc - 1]) > sizeof(path) - 1)
                errx(1, "%s: destination pathname too long", *argv);
-       (void)strcpy(path, argv[argc - 1]);
+       strcpy(path, argv[argc - 1]);
        baselen = strlen(path);
        endp = &path[baselen];
        if (!baselen || *(endp - 1) != '/') {
@@ -188,11 +188,11 @@ do_move(const char *from, const char *to)
                                printf("%s not overwritten\n", to);
                        return (0);
                } else if (iflg) {
-                       (void)fprintf(stderr, "overwrite %s? %s", to, YESNO);
+                       fprintf(stderr, "overwrite %s? %s", to, YESNO);
                        ask = 1;
                } else if (access(to, W_OK) && !stat(to, &sb) && isatty(STDIN_FILENO)) {
                        strmode(sb.st_mode, modep);
-                       (void)fprintf(stderr, "override %s%s%s/%s for %s? %s",
+                       fprintf(stderr, "override %s%s%s/%s for %s? %s",
                            modep + 1, modep[9] == ' ' ? "" : " ",
                            user_from_uid((unsigned long)sb.st_uid, 0),
                            group_from_gid((unsigned long)sb.st_gid, 0), to, YESNO);
@@ -203,7 +203,7 @@ do_move(const char *from, const char *to)
                        while (ch != '\n' && ch != EOF)
                                ch = getchar();
                        if (first != 'y' && first != 'Y') {
-                               (void)fprintf(stderr, "not overwritten\n");
+                               fprintf(stderr, "not overwritten\n");
                                return (0);
                        }
                }
@@ -292,7 +292,7 @@ fastcopy(const char *from, const char *to, struct stat *sbp)
                if (errno == EEXIST && unlink(to) == 0)
                        continue;
                warn("fastcopy: open() failed (to): %s", to);
-               (void)close(from_fd);
+               close(from_fd);
                return (1);
        }
        while ((nread = read(from_fd, bp, (size_t)blen)) > 0)
@@ -304,8 +304,8 @@ fastcopy(const char *from, const char *to, struct stat *sbp)
                warn("fastcopy: read() failed: %s", from);
 err:           if (unlink(to))
                        warn("%s: remove", to);
-               (void)close(from_fd);
-               (void)close(to_fd);
+               close(from_fd);
+               close(to_fd);
                return (1);
        }
 
@@ -323,7 +323,7 @@ err:                if (unlink(to))
        if (fchmod(to_fd, sbp->st_mode))
                warn("%s: set mode (was: 0%03o)", to, oldmode);
 
-       (void)close(from_fd);
+       close(from_fd);
        /*
         * XXX
         * NFS doesn't support chflags; ignore errors unless there's reason
@@ -360,7 +360,8 @@ static int
 copy(const char *from, const char *to)
 {
        struct stat sb;
-       int pid, status;
+       int status;
+       pid_t pid;
 
        if (lstat(to, &sb) == 0) {
                /* Destination path exists. */
@@ -383,7 +384,7 @@ copy(const char *from, const char *to)
        /* Copy source to destination. */
        if (!(pid = vfork())) {
                execl(_PATH_CP, "mv", vflg ? "-PRpv" : "-PRp", "--", from, to,
-                   (char *)NULL);
+                   NULL);
                _exit(EXEC_FAILED);
        }
        if (waitpid(pid, &status, 0) == -1) {
@@ -409,7 +410,7 @@ copy(const char *from, const char *to)
 
        /* Delete the source. */
        if (!(pid = vfork())) {
-               execl(_PATH_RM, "mv", "-rf", "--", from, (char *)NULL);
+               execl(_PATH_RM, "mv", "-rf", "--", from, NULL);
                _exit(EXEC_FAILED);
        }
        if (waitpid(pid, &status, 0) == -1) {
@@ -438,9 +439,9 @@ static void
 usage(void)
 {
 
-       (void)fprintf(stderr, "%s\n%s\n",
-                     "usage: mv [-f | -i | -n] [-hv] source target",
-                     "       mv [-f | -i | -n] [-v] source ... directory");
+       fprintf(stderr, "%s\n%s\n",
+               "usage: mv [-f | -i | -n] [-hv] source target",
+               "       mv [-f | -i | -n] [-v] source ... directory");
        exit(EX_USAGE);
 }