1 /* Construct a full pathname from a directory and a filename.
2 Copyright (C) 2001-2004, 2006-2007 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 2, or (at your option) any
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 /* Written by Bruno Haible <haible@clisp.cons.org>. */
30 /* Concatenate a directory filename, a relative filename and an optional
31 suffix. The directory may end with the directory separator. The second
32 argument may not start with the directory separator (it is relative).
33 Return a freshly allocated filename. */
35 concatenated_filename (const char *directory, const char *filename,
41 if (strcmp (directory, ".") == 0)
43 /* No need to prepend the directory. */
44 result = XNMALLOC (strlen (filename)
45 + (suffix != NULL ? strlen (suffix) : 0)
52 size_t directory_len = strlen (directory);
54 (directory_len > FILE_SYSTEM_PREFIX_LEN (directory)
55 && !ISSLASH (directory[directory_len - 1]));
56 result = XNMALLOC (directory_len + need_slash
58 + (suffix != NULL ? strlen (suffix) : 0)
61 memcpy (result, directory, directory_len);
62 p = result + directory_len;
66 p = stpcpy (p, filename);