Mercurial > hg > octave-lojdl > gnulib-hg
changeset 3245:0042efec5c38
(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.
author | Jim Meyering <jim@meyering.net> |
---|---|
date | Sat, 12 May 2001 15:45:43 +0000 |
parents | 5a129aed765a |
children | cb4b1284059f |
files | lib/path-concat.c |
diffstat | 1 files changed, 10 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/path-concat.c +++ b/lib/path-concat.c @@ -55,18 +55,7 @@ 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 @@ { 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 @@ } /* 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 @@ if (base_in_result) *base_in_result = p; - memcpy (p, base, base_len + 1); + memcpy (p, base, baselen); + p[baselen] = '\0'; return p_concat; }