summaryrefslogtreecommitdiffhomepage
path: root/coreutils
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>2000-01-08 21:16:29 +0000
committerErik Andersen <andersen@codepoet.org>2000-01-08 21:16:29 +0000
commit1dbc17f630fa92e2ee3ac0f1e2bccb6adf6f9032 (patch)
treef86b3ad6f14114543da369473d0f4b20a4fdc436 /coreutils
parent5338ce19c873e7fc2a312eb0fd6443514b5cdb05 (diff)
Fix cp and mv so 'cp foo/README bar' where foo and bar are directories,
and README is a file. -Erik
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/cp.c7
-rw-r--r--coreutils/mv.c7
2 files changed, 12 insertions, 2 deletions
diff --git a/coreutils/cp.c b/coreutils/cp.c
index 4af73c274..e96012d50 100644
--- a/coreutils/cp.c
+++ b/coreutils/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));
diff --git a/coreutils/mv.c b/coreutils/mv.c
index 92c40c9b7..467a360de 100644
--- a/coreutils/mv.c
+++ b/coreutils/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));