fleshed out a bit more... just wanted to put the current
[oweals/busybox.git] / mv.c
diff --git a/mv.c b/mv.c
index 92c40c9b7866bf8f8b1f2f9f9a0345e9b32783ae..467a360dea59121875842a39fbfbc88b07c868ab 100644 (file)
--- a/mv.c
+++ b/mv.c
@@ -40,6 +40,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 ) {
@@ -50,7 +51,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, TRUE, TRUE));