blob: c699a84f7e57376321eb5374560d3d64401271cd [file] [log] [blame]
Eric Andersene5dfced2001-04-09 22:48:12 +00001/*
2 * busybox library eXtendet funcion
3 *
4 * concatenate path and file name to new allocation buffer,
5 * not addition '/' if path name already have '/'
6 *
7*/
8
Manuel Novoa III a2949aa2001-06-29 18:59:32 +00009#include <string.h>
Eric Andersene5dfced2001-04-09 22:48:12 +000010#include "libbb.h"
11
12extern char *concat_path_file(const char *path, const char *filename)
13{
14 char *outbuf;
Eric Andersenc911a432001-05-15 17:42:16 +000015 char *lc;
Eric Andersen5a071bc2001-07-07 04:27:35 +000016
17 if (!path)
18 path="";
Eric Andersenc911a432001-05-15 17:42:16 +000019 lc = last_char_is(path, '/');
Eric Andersen4ad13e52001-05-07 23:01:32 +000020 if (filename[0] == '/')
21 filename++;
22 outbuf = xmalloc(strlen(path)+strlen(filename)+1+(lc==NULL));
Eric Andersen5a071bc2001-07-07 04:27:35 +000023 sprintf(outbuf, "%s%s%s", path, (lc==NULL)? "/" : "", filename);
24
Eric Andersene5dfced2001-04-09 22:48:12 +000025 return outbuf;
26}