diff options
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/cp.c | 14 | ||||
-rw-r--r-- | coreutils/mv.c | 7 |
2 files changed, 11 insertions, 10 deletions
diff --git a/coreutils/cp.c b/coreutils/cp.c index 6ca66e642..4016fc760 100644 --- a/coreutils/cp.c +++ b/coreutils/cp.c | |||
@@ -41,21 +41,24 @@ static int preserveFlag = FALSE; | |||
41 | static const char *srcName; | 41 | static const char *srcName; |
42 | static const char *destName; | 42 | static const char *destName; |
43 | static const char *skipName; | 43 | static const char *skipName; |
44 | static int dirFlag = FALSE; | ||
44 | 45 | ||
45 | 46 | ||
46 | static int fileAction(const char *fileName) | 47 | static int fileAction(const char *fileName, struct stat* statbuf) |
47 | { | 48 | { |
48 | char newdestName[NAME_MAX]; | 49 | char newdestName[NAME_MAX]; |
49 | strcpy(newdestName, destName); | 50 | strcpy(newdestName, destName); |
50 | strcat(newdestName, strstr(fileName, skipName)); | 51 | if (dirFlag==TRUE && newdestName[strlen(newdestName)-1]!= '/' ) { |
52 | strcat(newdestName, "/"); | ||
53 | if ( skipName != NULL) | ||
54 | strcat(newdestName, strstr(fileName, skipName)); | ||
55 | } | ||
51 | return (copyFile(fileName, newdestName, preserveFlag, followLinks)); | 56 | return (copyFile(fileName, newdestName, preserveFlag, followLinks)); |
52 | } | 57 | } |
53 | 58 | ||
54 | extern int cp_main(int argc, char **argv) | 59 | extern int cp_main(int argc, char **argv) |
55 | { | 60 | { |
56 | 61 | ||
57 | int dirFlag; | ||
58 | |||
59 | if (argc < 3) { | 62 | if (argc < 3) { |
60 | fprintf(stderr, "Usage: %s", cp_usage); | 63 | fprintf(stderr, "Usage: %s", cp_usage); |
61 | exit (FALSE); | 64 | exit (FALSE); |
@@ -91,10 +94,9 @@ extern int cp_main(int argc, char **argv) | |||
91 | 94 | ||
92 | 95 | ||
93 | destName = argv[argc - 1]; | 96 | destName = argv[argc - 1]; |
94 | |||
95 | dirFlag = isDirectory(destName); | 97 | dirFlag = isDirectory(destName); |
96 | 98 | ||
97 | if ((argc > 3) && !dirFlag) { | 99 | if ((argc > 3) && dirFlag==FALSE) { |
98 | fprintf(stderr, "%s: not a directory\n", destName); | 100 | fprintf(stderr, "%s: not a directory\n", destName); |
99 | exit (FALSE); | 101 | exit (FALSE); |
100 | } | 102 | } |
diff --git a/coreutils/mv.c b/coreutils/mv.c index df56206a3..10a082210 100644 --- a/coreutils/mv.c +++ b/coreutils/mv.c | |||
@@ -41,7 +41,7 @@ extern int mv_main (int argc, char **argv) | |||
41 | 41 | ||
42 | if (argc < 3) { | 42 | if (argc < 3) { |
43 | fprintf (stderr, "Usage: %s %s", *argv, mv_usage); | 43 | fprintf (stderr, "Usage: %s %s", *argv, mv_usage); |
44 | return (FALSE); | 44 | exit (FALSE); |
45 | } | 45 | } |
46 | lastArg = argv[argc - 1]; | 46 | lastArg = argv[argc - 1]; |
47 | 47 | ||
@@ -49,8 +49,7 @@ extern int mv_main (int argc, char **argv) | |||
49 | 49 | ||
50 | if ((argc > 3) && !dirFlag) { | 50 | if ((argc > 3) && !dirFlag) { |
51 | fprintf (stderr, "%s: not a directory\n", lastArg); | 51 | fprintf (stderr, "%s: not a directory\n", lastArg); |
52 | 52 | exit (FALSE); | |
53 | return (FALSE); | ||
54 | } | 53 | } |
55 | 54 | ||
56 | while (argc-- > 2) { | 55 | while (argc-- > 2) { |
@@ -80,5 +79,5 @@ extern int mv_main (int argc, char **argv) | |||
80 | if (unlink (srcName) < 0) | 79 | if (unlink (srcName) < 0) |
81 | perror (srcName); | 80 | perror (srcName); |
82 | } | 81 | } |
83 | return (TRUE); | 82 | exit (TRUE); |
84 | } | 83 | } |