diff --git a/bin/cp/cp.1 b/bin/cp/cp.1 index 4841e41c666b..fad0c0acc72e 100644 --- a/bin/cp/cp.1 +++ b/bin/cp/cp.1 @@ -47,16 +47,14 @@ .Fl R .Op Fl H | Fl L | Fl P .Oc -.Op Fl f | i -.Op Fl p +.Op Fl fip .Ar source_file target_file .Nm cp .Oo .Fl R .Op Fl H | Fl L | Fl P .Oc -.Op Fl f | i -.Op Fl p +.Op Fl fip .Ar source_file ... target_directory .Sh DESCRIPTION In the first synopsis form, the @@ -107,25 +105,18 @@ For each existing destination pathname, remove it and create a new file, without prompting for confirmation regardless of its permissions. (The -.Fl f -option overrides any previous .Fl i -options.) +option is ignored if the +.Fl f +option is specified.) .It Fl i Causes .Nm cp to write a prompt to the standard error output before copying a file that would overwrite an existing file. If the response from the standard input begins with the character -.Sq Li y -or -.Sq Li Y , +.Sq Li y , the file copy is attempted. -(The -.Fl i -option overrides any previous -.Fl f -options.) .It Fl p Causes .Nm cp diff --git a/bin/cp/cp.c b/bin/cp/cp.c index b668d75da131..cfbcd5636f3a 100644 --- a/bin/cp/cp.c +++ b/bin/cp/cp.c @@ -86,7 +86,7 @@ static char sccsid[] = "@(#)cp.c 8.2 (Berkeley) 4/1/94"; PATH_T to = { to.p_path, "" }; uid_t myuid; -int Rflag, iflag, pflag, rflag, fflag; +int Rflag, iflag, pflag, rflag; int myumask; enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE }; @@ -105,8 +105,7 @@ main(argc, argv) char *target; Hflag = Lflag = Pflag = Rflag = 0; - fflag = iflag = rflag = pflag = 0; - while ((ch = getopt(argc, argv, "HLPRfipr?")) != EOF) + while ((ch = getopt(argc, argv, "HLPRfipr")) != EOF) switch (ch) { case 'H': Hflag = 1; @@ -125,11 +124,9 @@ main(argc, argv) break; case 'f': iflag = 0; - fflag = 1; break; case 'i': - iflag = isatty(STDIN_FILENO); - fflag = 0; + iflag = isatty(fileno(stdin)); break; case 'p': pflag = 1; diff --git a/bin/cp/extern.h b/bin/cp/extern.h index 6ca9910c3eb5..d97d76aa46d6 100644 --- a/bin/cp/extern.h +++ b/bin/cp/extern.h @@ -42,7 +42,7 @@ typedef struct { extern PATH_T to; extern uid_t myuid; -extern int iflag, pflag, fflag, myumask; +extern int iflag, pflag, myumask; #include diff --git a/bin/cp/utils.c b/bin/cp/utils.c index ca7017c8e451..0aa480d7b163 100644 --- a/bin/cp/utils.c +++ b/bin/cp/utils.c @@ -86,21 +86,12 @@ copy_file(entp, dne) checkch = ch = getchar(); while (ch != '\n' && ch != EOF) ch = getchar(); - if (checkch != 'y' && checkch != 'Y') { + if (checkch != 'y') { (void)close(from_fd); return (0); } } - - if (fflag) { - /* remove existing destination file name, - * create a new file */ - (void)unlink(to.p_path); - to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT, - fs->st_mode & ~(S_ISUID | S_ISGID)); - } else - /* overwrite existing destination file name */ - to_fd = open(to.p_path, O_WRONLY | O_TRUNC, 0); + to_fd = open(to.p_path, O_WRONLY | O_TRUNC, 0); } else to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT, fs->st_mode & ~(S_ISUID | S_ISGID)); @@ -290,7 +281,7 @@ void usage() { (void)fprintf(stderr, "%s\n%s\n", -"usage: cp [-R [-H | -L | -P] [-f | -i] [-p] src target", -" cp [-R [-H | -L | -P] [-f | -i] [-p] src1 ... srcN directory"); +"usage: cp [-R [-H | -L | -P] [-fip] src target", +" cp [-R [-H | -L | -P] [-fip] src1 ... srcN directory"); exit(1); } diff --git a/bin/mv/mv.1 b/bin/mv/mv.1 index eb9634fe7a59..f113a3ac311a 100644 --- a/bin/mv/mv.1 +++ b/bin/mv/mv.1 @@ -77,25 +77,17 @@ The following options are available: Do not prompt for confirmation before overwriting the destination path. (The -.Fl f -option overrides any previous .Fl i -options.) +option is ignored if the +.Fl f +option is specified.) .It Fl i Causes .Nm mv to write a prompt to standard error before moving a file that would overwrite an existing file. -If the response from the standard input begins with the character -.Sq Li y -or -.Sq Li Y , +If the response from the standard input begins with the character ``y'', the move is attempted. -(The -.Fl i -option overrides any previous -.Fl f -options.) .El .Pp It is an error for either the @@ -129,7 +121,6 @@ The utility exits 0 on success, and >0 if an error occurs. .Sh SEE ALSO .Xr cp 1 , -.Xr rm 1 , .Xr symlink 7 .Sh STANDARDS The diff --git a/bin/mv/mv.c b/bin/mv/mv.c index 0a3d35e6a9f4..28da455ecd6f 100644 --- a/bin/mv/mv.c +++ b/bin/mv/mv.c @@ -79,17 +79,13 @@ main(argc, argv) int ch; char path[MAXPATHLEN + 1]; - fflg = iflg = 0; - - while ((ch = getopt(argc, argv, "-if?")) != EOF) + while ((ch = getopt(argc, argv, "-if")) != EOF) switch (ch) { case 'i': - iflg = isatty(STDIN_FILENO); - fflg = 0; + iflg = 1; break; case 'f': fflg = 1; - iflg = 0; break; case '-': /* Undocumented; for compatibility. */ goto endarg; @@ -156,13 +152,6 @@ do_move(from, to) * make sure the user wants to clobber it. */ if (!fflg && !access(to, F_OK)) { - - /* prompt only if source exist */ - if (lstat(from, &sb) == -1) { - warn("%s", from); - return (1); - } - ask = 0; if (iflg) { (void)fprintf(stderr, "overwrite %s? ", to); @@ -178,7 +167,7 @@ do_move(from, to) if (ask) { if ((ch = getchar()) != EOF && ch != '\n') while (getchar() != '\n'); - if (ch != 'y' && ch != 'Y') + if (ch != 'y') return (0); } } @@ -314,6 +303,6 @@ void usage() { (void)fprintf(stderr, -"usage: mv [-if] src target;\n or: mv [-i | -f] src1 ... srcN directory\n"); +"usage: mv [-if] src target;\n or: mv [-if] src1 ... srcN directory\n"); exit(1); } diff --git a/bin/rm/rm.c b/bin/rm/rm.c index f9ce8d1c2434..ffe565505241 100644 --- a/bin/rm/rm.c +++ b/bin/rm/rm.c @@ -30,7 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: rm.c,v 1.7 1996/02/18 19:00:59 wosch Exp $ + * $Id: rm.c,v 1.6 1995/04/13 13:35:09 ache Exp $ */ #ifndef lint @@ -81,8 +81,7 @@ main(argc, argv) { int ch, rflag; - rflag = 0; - + Pflag = rflag = 0; while ((ch = getopt(argc, argv, "dfiPRr")) != EOF) switch(ch) { case 'd': @@ -103,6 +102,7 @@ main(argc, argv) case 'r': /* Compatibility. */ rflag = 1; break; + case '?': default: usage(); } @@ -378,7 +378,7 @@ check(path, name, sp) first = ch = getchar(); while (ch != '\n' && ch != EOF) ch = getchar(); - return (first == 'y' || first == 'Y'); + return (first == 'y'); } #define ISDOT(a) ((a)[0] == '.' && (!(a)[1] || ((a)[1] == '.' && !(a)[2]))) @@ -410,6 +410,6 @@ void usage() { - (void)fprintf(stderr, "usage: rm [-dfiPRr] file ...\n"); + (void)fprintf(stderr, "usage: rm [-dfiRr] file ...\n"); exit(1); }