blob: 415b6a2fb48d42d2b35b3e6dfc0b7d3234caccb4 [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,
Eric Andersene5dfced2001-04-09 22:48:12 +000012 * not addition '/' if path name already have '/'
Eric Andersene5dfced2001-04-09 22:48:12 +000013*/
14
Manuel Novoa III a2949aa2001-06-29 18:59:32 +000015#include <string.h>
Eric Andersene5dfced2001-04-09 22:48:12 +000016#include "libbb.h"
17
Rob Landleydfba7412006-03-06 20:47:33 +000018char *concat_path_file(const char *path, const char *filename)
Eric Andersene5dfced2001-04-09 22:48:12 +000019{
Eric Andersenc911a432001-05-15 17:42:16 +000020 char *lc;
Eric Andersen5a071bc2001-07-07 04:27:35 +000021
22 if (!path)
Mike Frysinger9dc93ac2005-05-09 21:51:15 +000023 path = "";
Eric Andersenc911a432001-05-15 17:42:16 +000024 lc = last_char_is(path, '/');
Eric Andersen34506362001-08-02 05:02:46 +000025 while (*filename == '/')
Eric Andersen4ad13e52001-05-07 23:01:32 +000026 filename++;
"Vladimir N. Oleynik"39a841c2005-09-29 16:18:57 +000027 return bb_xasprintf("%s%s%s", path, (lc==NULL ? "/" : ""), filename);
Eric Andersene5dfced2001-04-09 22:48:12 +000028}