summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1997-11-12 16:18:23 +0000
committerJim Meyering <jim@meyering.net>1997-11-12 16:18:23 +0000
commit4d1e1b28f830187f5cd7d28bed532f1cb0826b88 (patch)
tree29822e301db501372ef38d5140267bcaecbc11f0 /lib
parent992fc3869f2298e6f7614c2203aaa140a0af085a (diff)
downloadcoreutils-4d1e1b28f830187f5cd7d28bed532f1cb0826b88.tar.xz
(path_concat): Use mempcpy, not stpcpy.
Diffstat (limited to 'lib')
-rw-r--r--lib/path-concat.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/path-concat.c b/lib/path-concat.c
index 54509125c..c7f041bbd 100644
--- a/lib/path-concat.c
+++ b/lib/path-concat.c
@@ -1,5 +1,5 @@
/* path-concat.c -- concatenate two arbitrary pathnames
- Copyright (C) 1996 Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -18,11 +18,17 @@
/* Written by Jim Meyering. */
#ifdef HAVE_CONFIG_H
-#include <config.h>
+# include <config.h>
#endif
+#ifndef HAVE_MEMPCPY
+# define mempcpy(D, S, N) ((void *) ((char *) memcpy (D, S, N) + (N)))
+#endif
+
+#include <stdio.h>
+#include <sys/types.h>
+
char *malloc ();
-char *stpcpy ();
/* Concatenate two pathname components, DIR and BASE, in newly-allocated
storage and return the result. Return 0 if out of memory. Add a slash
@@ -40,22 +46,24 @@ path_concat (dir, base, base_in_result)
{
char *p;
char *p_concat;
+ size_t base_len = strlen (base);
+ size_t dir_len = strlen (dir);
- p_concat = malloc (strlen (dir) + strlen (base) + 2);
+ p_concat = malloc (dir_len + base_len + 2);
if (!p_concat)
return 0;
- p = stpcpy (p_concat, dir);
+ p = mempcpy (p_concat, dir, dir_len);
if (*(p - 1) == '/' && *base == '/')
--p;
else if (*(p - 1) != '/' && *base != '/')
- p = stpcpy (p, "/");
+ *p++ = '/';
if (base_in_result)
*base_in_result = p;
- stpcpy (p, base);
+ mempcpy (p, base, base_len + 1);
return p_concat;
}