summaryrefslogtreecommitdiff
path: root/src/cp.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2000-07-23 10:54:01 +0000
committerJim Meyering <jim@meyering.net>2000-07-23 10:54:01 +0000
commit9993d4141c63ff93bca1a30287016b71cc00e427 (patch)
tree2303a281c79af95b8d155a3c2fab616ab0e542a1 /src/cp.c
parente66e1f94bb28fd1017de6f38533e52822926e9b1 (diff)
downloadcoreutils-9993d4141c63ff93bca1a30287016b71cc00e427.tar.xz
Fix cp so that `cp -r DIR1/ DIR2' works once again.
(ASSIGN_BASENAME_STRDUPA): New macro. (do_copy): Use it here (so we always strip trailing slashes before calling base_name).
Diffstat (limited to 'src/cp.c')
-rw-r--r--src/cp.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/cp.c b/src/cp.c
index bde3209d6..1192d0cbc 100644
--- a/src/cp.c
+++ b/src/cp.c
@@ -37,6 +37,16 @@
#include "path-concat.h"
#include "quote.h"
+#define ASSIGN_BASENAME_STRDUPA(Dest, File_name) \
+ do \
+ { \
+ char *tmp_abns_; \
+ ASSIGN_STRDUPA (tmp_abns_, (File_name)); \
+ strip_trailing_slashes (tmp_abns_); \
+ Dest = base_name (tmp_abns_); \
+ } \
+ while (0)
+
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "cp"
@@ -498,7 +508,6 @@ do_copy (int n_files, char **file, const char *target_directory,
for (i = 0; i < n_files; i++)
{
- char *ap;
char *dst_path;
int parent_exists = 1; /* True if dir_name (dst_path) exists. */
struct dir_attr *attr_list;
@@ -528,13 +537,14 @@ do_copy (int n_files, char **file, const char *target_directory,
}
else
{
+ char *arg_base;
/* Append the last component of `arg' to `dest'. */
- ap = base_name (arg);
+ ASSIGN_BASENAME_STRDUPA (arg_base, arg);
/* For `cp -R source/.. dest', don't copy into `dest/..'. */
- dst_path = (STREQ (ap, "..")
+ dst_path = (STREQ (arg_base, "..")
? xstrdup (dest)
- : path_concat (dest, ap, NULL));
+ : path_concat (dest, arg_base, NULL));
}
if (!parent_exists)
@@ -614,14 +624,8 @@ do_copy (int n_files, char **file, const char *target_directory,
&& !S_ISDIR (source_stats.st_mode))
{
char *source_base;
- char *tmp_source;
-
- tmp_source = (char *) alloca (strlen (source) + 1);
- strcpy (tmp_source, source);
- if (remove_trailing_slashes)
- strip_trailing_slashes (tmp_source);
- source_base = base_name (tmp_source);
+ ASSIGN_BASENAME_STRDUPA (source_base, source);
new_dest = (char *) alloca (strlen (dest)
+ strlen (source_base) + 1);
stpcpy (stpcpy (new_dest, dest), source_base);