1/* Concatenate path components.
2 Copyright (C) 2018-2019 Free Software Foundation, Inc.
3
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 3 of the License, or any
7 later version.
8
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.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17/* Written by Akim Demaille <akim@lrde.epita.fr>. */
18
19#include <config.h>
20
21/* Specification. */
22#include "path-join.h"
23
24#include <concat-filename.h> /* xconcatenated_filename */
25#include <filename.h> /* IS_ABSOLUTE_PATH */
26#include <xalloc.h> /* xstrdup */
27
28char *
29xpath_join (const char *path1, const char *path2)
30{
31 if (!path2 || !*path2)
32 return xstrdup (path1);
33 else if (IS_ABSOLUTE_PATH (path2))
34 return xstrdup (path2);
35 else
36 return xconcatenated_filename (path1, path2, NULL);
37}
38