projects
/
unix-history
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
tags
|
clone url
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
L option; use lstat by default
[unix-history]
/
usr
/
src
/
bin
/
mv
/
mv.c
diff --git
a/usr/src/bin/mv/mv.c
b/usr/src/bin/mv/mv.c
index
04fea76
..
274abdd
100644
(file)
--- a/
usr/src/bin/mv/mv.c
+++ b/
usr/src/bin/mv/mv.c
@@
-1,4
+1,4
@@
-static char *sccsid = "@(#)mv.c 4.
1 (Berkeley) %G%
";
+static char *sccsid = "@(#)mv.c 4.
5 (Berkeley) 82/02/11
";
/*
* mv file1 file2
*/
/*
* mv file1 file2
*/
@@
-6,7
+6,6
@@
static char *sccsid = "@(#)mv.c 4.1 (Berkeley) %G%";
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include <sys/dir.h>
#include <signal.h>
#define DOT "."
#include <signal.h>
#define DOT "."
@@
-31,15
+30,23
@@
main(argc, argv)
register char *argv[];
{
register i, r;
register char *argv[];
{
register i, r;
+ register char *arg;
/* get the flag(s) */
if (argc < 2)
goto usage;
/* get the flag(s) */
if (argc < 2)
goto usage;
-
if (
*argv[1] == '-') {
+
while (argc>1 &&
*argv[1] == '-') {
argc--;
argc--;
- while (*++argv[1] != '\0')
- switch (*argv[1]) {
+ arg = *++argv;
+
+ /*
+ * all files following a null option are considered file names
+ */
+ if (*(arg+1) == '\0') break;
+
+ while (*++arg != '\0')
+ switch (*arg) {
/* interactive mode */
case 'i':
/* interactive mode */
case 'i':
@@
-55,7
+62,6
@@
register char *argv[];
default:
goto usage;
}
default:
goto usage;
}
- argv++;
}
if (argc < 3)
goto usage;
}
if (argc < 3)
goto usage;
@@
-77,7
+83,7
@@
register char *argv[];
r |= move(argv[i], argv[argc-1]);
return(r);
usage:
r |= move(argv[i], argv[argc-1]);
return(r);
usage:
- fprintf(stderr, "usage: mv
f1 f2; or mv d1 d2; or mv
f1 ... fn d1\n");
+ fprintf(stderr, "usage: mv
[-if] f1 f2; or mv [-if] d1 d2; or mv [-if]
f1 ... fn d1\n");
return(1);
}
return(1);
}
@@
-169,22
+175,16
@@
char *source, *target;
if ((s2.st_mode&S_IFMT) != S_IFDIR) {
fprintf(stderr, "mv: %s exists\n", target);
return(1);
if ((s2.st_mode&S_IFMT) != S_IFDIR) {
fprintf(stderr, "mv: %s exists\n", target);
return(1);
- } else if (iflag && !fflag) {
- fprintf(stderr, "remove %s? ", target);
- cc = c = getchar();
- while (c != '\n' && c != EOF)
- c = getchar();
- if (cc != 'y')
- return(1);
}
}
- if (strlen(target) > MAXN-DIRSIZ-2) {
+ p = dname(source);
+ if (strlen(target) > MAXN-strlen(p)-2) {
fprintf(stderr, "mv :target name too long\n");
return(1);
}
strcpy(buf, target);
target = buf;
strcat(buf, SDELIM);
fprintf(stderr, "mv :target name too long\n");
return(1);
}
strcpy(buf, target);
target = buf;
strcat(buf, SDELIM);
- strcat(buf,
dname(source)
);
+ strcat(buf,
p
);
if (stat(target, &s2) >= 0) {
fprintf(stderr, "mv: %s exists\n", buf);
return(1);
if (stat(target, &s2) >= 0) {
fprintf(stderr, "mv: %s exists\n", buf);
return(1);
@@
-211,10
+211,6
@@
char *source, *target;
fprintf(stderr, "mv: no write access to %s\n", pname(source));
return(1);
}
fprintf(stderr, "mv: no write access to %s\n", pname(source));
return(1);
}
- if (access(source, 2) < 0) {
- fprintf(stderr, "mv: no write access to %s\n", source);
- return(1);
- }
if (s1.st_dev != s2.st_dev) {
fprintf(stderr, "mv: cannot move directories across devices\n");
return(1);
if (s1.st_dev != s2.st_dev) {
fprintf(stderr, "mv: cannot move directories across devices\n");
return(1);