X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fpath-concat.c;h=86579b7369fd7cce6b446e6920db45dabf10140a;hb=024e00dc5ac2b025d28dffa04585c95a4c6f4cc8;hp=ce74ed1334ee1a3778ed7fcc281138bfa7c97456;hpb=8ddb64cf1508f8f7d64d1e23285a7ce6f2bbd7fd;p=gnulib.git diff --git a/lib/path-concat.c b/lib/path-concat.c index ce74ed133..86579b736 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, 1998 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 @@ -17,12 +17,21 @@ /* Written by Jim Meyering. */ -#ifdef HAVE_CONFIG_H -#include +#if HAVE_CONFIG_H +# include #endif +#ifndef HAVE_MEMPCPY +# define mempcpy(D, S, N) ((void *) ((char *) memcpy (D, S, N) + (N))) +#endif + +#include +#if HAVE_STRING_H +# include +#endif +#include + 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 @@ -37,22 +46,24 @@ path_concat (const char *dir, const char *base, char **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); + memcpy (p, base, base_len + 1); return p_concat; }