summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2001-05-12 15:45:43 +0000
committerJim Meyering <jim@meyering.net>2001-05-12 15:45:43 +0000
commitf6e82b7dea359a964166ca7bd192fd3782eba4b9 (patch)
tree2914feba502858c3fd1e2c8a7f454382edc24244
parent1450c855b62084c0e490e7738282932425cf3a9c (diff)
downloadcoreutils-f6e82b7dea359a964166ca7bd192fd3782eba4b9.tar.xz
(DIRECTORY_SEPARATOR, FILESYSTEM_PREFIX_LEN, ISSLASH): Remove; now in dirname.h.
(path_concat): Use base_len to compute base length, not strlen; this means we cannot rely on memcpy to null-terminate.
-rw-r--r--lib/path-concat.c30
1 files changed, 10 insertions, 20 deletions
diff --git a/lib/path-concat.c b/lib/path-concat.c
index e6f44d3e8..622d5d73b 100644
--- a/lib/path-concat.c
+++ b/lib/path-concat.c
@@ -55,18 +55,7 @@ char *malloc ();
char *strdup ();
#endif
-#ifndef DIRECTORY_SEPARATOR
-# define DIRECTORY_SEPARATOR '/'
-#endif
-
-#ifndef FILESYSTEM_PREFIX_LEN
-# define FILESYSTEM_PREFIX_LEN(Filename) 0
-#endif
-
-#ifndef ISSLASH
-# define ISSLASH(C) ((C) == DIRECTORY_SEPARATOR)
-#endif
-
+#include "dirname.h"
#include "xalloc.h"
#include "path-concat.h"
@@ -88,8 +77,8 @@ path_concat (const char *dir, const char *base, char **base_in_result)
{
char *p;
char *p_concat;
- size_t base_len;
- size_t dir_len;
+ size_t baselen;
+ size_t dirlen;
if (!dir)
{
@@ -100,16 +89,16 @@ path_concat (const char *dir, const char *base, char **base_in_result)
}
/* DIR is not empty. */
- base_len = strlen (base);
- dir_len = strlen (dir);
+ baselen = base_len (base);
+ dirlen = strlen (dir);
- p_concat = malloc (dir_len + base_len + 2);
+ p_concat = malloc (dirlen + baselen + 2);
if (!p_concat)
return 0;
- p = mempcpy (p_concat, dir, dir_len);
+ p = mempcpy (p_concat, dir, dirlen);
- if (dir_len > FILESYSTEM_PREFIX_LEN (dir))
+ if (FILESYSTEM_PREFIX_LEN (dir) < dirlen)
{
if (ISSLASH (*(p - 1)) && ISSLASH (*base))
--p;
@@ -120,7 +109,8 @@ path_concat (const char *dir, const char *base, char **base_in_result)
if (base_in_result)
*base_in_result = p;
- memcpy (p, base, base_len + 1);
+ memcpy (p, base, baselen);
+ p[baselen] = '\0';
return p_concat;
}