aboutsummaryrefslogtreecommitdiff
path: root/cp.c
diff options
context:
space:
mode:
Diffstat (limited to 'cp.c')
-rw-r--r--cp.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/cp.c b/cp.c
index 6ca66e642..4016fc760 100644
--- a/cp.c
+++ b/cp.c
@@ -41,21 +41,24 @@ static int preserveFlag = FALSE;
41static const char *srcName; 41static const char *srcName;
42static const char *destName; 42static const char *destName;
43static const char *skipName; 43static const char *skipName;
44static int dirFlag = FALSE;
44 45
45 46
46static int fileAction(const char *fileName) 47static 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
54extern int cp_main(int argc, char **argv) 59extern 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 }