blob: 00233ad9a37ebead3703e9d0b3d4f27afd204da6 [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 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 * USA
22 */
23
24/* concatenate path and file name to new allocation buffer,
Eric Andersene5dfced2001-04-09 22:48:12 +000025 * not addition '/' if path name already have '/'
Eric Andersene5dfced2001-04-09 22:48:12 +000026*/
27
Manuel Novoa III a2949aa2001-06-29 18:59:32 +000028#include <string.h>
Eric Andersene5dfced2001-04-09 22:48:12 +000029#include "libbb.h"
30
31extern char *concat_path_file(const char *path, const char *filename)
32{
33 char *outbuf;
Eric Andersenc911a432001-05-15 17:42:16 +000034 char *lc;
Eric Andersen5a071bc2001-07-07 04:27:35 +000035
36 if (!path)
Mike Frysinger9dc93ac2005-05-09 21:51:15 +000037 path = "";
Eric Andersenc911a432001-05-15 17:42:16 +000038 lc = last_char_is(path, '/');
Eric Andersen34506362001-08-02 05:02:46 +000039 while (*filename == '/')
Eric Andersen4ad13e52001-05-07 23:01:32 +000040 filename++;
Mike Frysinger9dc93ac2005-05-09 21:51:15 +000041 bb_xasprintf(&outbuf, "%s%s%s", path, (lc==NULL ? "/" : ""), filename);
Eric Andersen5a071bc2001-07-07 04:27:35 +000042
Eric Andersene5dfced2001-04-09 22:48:12 +000043 return outbuf;
44}