From b74c9a14fdda36b4b47b29bb19ae4320d079c633 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Wed, 12 Nov 1997 17:18:55 +0000 Subject: [PATCH] (copy_dir): Use path_concat rather than open-coding it. --- src/copy.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/copy.c b/src/copy.c index c65fadb..24f5756 100644 --- a/src/copy.c +++ b/src/copy.c @@ -13,6 +13,7 @@ #include "savedir.h" #include "copy.h" #include "cp-hash.h" +#include "path-concat.h" /* On Linux (from slackware-1.2.13 to 2.0.2?) there is no lchown function. To change ownership of symlinks, you must run chown with an effective @@ -91,13 +92,10 @@ copy_dir (const char *src_path_in, const char *dst_path_in, int new_dst, namep = name_space; while (*namep != '\0') { - int fn_length = strlen (namep) + 1; - - dst_path = xmalloc (strlen (dst_path_in) + fn_length + 1); - src_path = xmalloc (strlen (src_path_in) + fn_length + 1); - - stpcpy (stpcpy (stpcpy (src_path, src_path_in), "/"), namep); - stpcpy (stpcpy (stpcpy (dst_path, dst_path_in), "/"), namep); + src_path = path_concat (src_path_in, namep, NULL); + dst_path = path_concat (dst_path_in, namep, NULL); + if (dst_path == NULL || src_path == NULL) + error (1, 0, _("virtual memory exhausted")); ret |= copy_internal (src_path, dst_path, new_dst, src_sb->st_dev, ancestors, x); @@ -108,7 +106,7 @@ copy_dir (const char *src_path_in, const char *dst_path_in, int new_dst, free (src_path); - namep += fn_length; + namep += strlen (namep) + 1; } free (name_space); return -ret; -- 2.7.4