blob: 9aae601a4cca7ad100a561e78e383c93c0b1f079 [file] [log] [blame]
Eric Andersenbdfd0d72001-10-24 05:00:29 +00001/* vi: set sw=4 ts=4: */
Eric Andersene5dfced2001-04-09 22:48:12 +00002/*
Eric Andersenbdfd0d72001-10-24 05:00:29 +00003 * Utility routines.
Eric Andersene5dfced2001-04-09 22:48:12 +00004 *
Eric Andersenc7bda1c2004-03-15 08:29:22 +00005 * Copyright (C) many different people.
Eric Andersencb81e642003-07-14 21:21:08 +00006 * If you wrote this, please acknowledge your work.
Eric Andersenbdfd0d72001-10-24 05:00:29 +00007 *
"Robert P. J. Day"5d8843e2006-07-10 11:41:19 +00008 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Eric Andersenbdfd0d72001-10-24 05:00:29 +00009 */
10
11/* concatenate path and file name to new allocation buffer,
Denis Vlasenko5c759602006-10-28 12:37:16 +000012 * not adding '/' if path name already has '/'
Eric Andersene5dfced2001-04-09 22:48:12 +000013*/
14
15#include "libbb.h"
16
Rob Landleydfba7412006-03-06 20:47:33 +000017char *concat_path_file(const char *path, const char *filename)
Eric Andersene5dfced2001-04-09 22:48:12 +000018{
Eric Andersenc911a432001-05-15 17:42:16 +000019 char *lc;
Eric Andersen5a071bc2001-07-07 04:27:35 +000020
21 if (!path)
Mike Frysinger9dc93ac2005-05-09 21:51:15 +000022 path = "";
Eric Andersenc911a432001-05-15 17:42:16 +000023 lc = last_char_is(path, '/');
Eric Andersen34506362001-08-02 05:02:46 +000024 while (*filename == '/')
Eric Andersen4ad13e52001-05-07 23:01:32 +000025 filename++;
Rob Landleyd921b2e2006-08-03 15:41:12 +000026 return xasprintf("%s%s%s", path, (lc==NULL ? "/" : ""), filename);
Eric Andersene5dfced2001-04-09 22:48:12 +000027}