Making note of my changes
[oweals/busybox.git] / cp.c
diff --git a/cp.c b/cp.c
index 4af73c274633ba574beac6cc7ac82195e3fe323a..e96012d500fea7916d4b84ae2ad6545ef521a26d 100644 (file)
--- a/cp.c
+++ b/cp.c
@@ -48,6 +48,7 @@ static int srcDirFlag = FALSE;
 static int fileAction(const char *fileName, struct stat* statbuf)
 {
     char newdestName[NAME_MAX];
+    char* newsrcName = NULL;
 
     strcpy(newdestName, destName);
     if ( srcDirFlag == TRUE ) {
@@ -62,7 +63,11 @@ static int fileAction(const char *fileName, struct stat* statbuf)
        if (newdestName[strlen(newdestName)-1] != '/' ) {
            strcat(newdestName, "/");
        }
-       strcat(newdestName, srcName);
+       newsrcName = strrchr(srcName, '/');
+       if (newsrcName && *newsrcName != '\0')
+           strcat(newdestName, newsrcName);
+       else
+           strcat(newdestName, srcName);
     }
     
     return (copyFile(fileName, newdestName, preserveFlag, followLinks));