blob: 12a57c837391ba387312641de3c0c19e72370671 [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
9#include "libbb.h"
10
11extern char *concat_path_file(const char *path, const char *filename)
12{
13 char *outbuf;
Eric Andersenc911a432001-05-15 17:42:16 +000014 char *lc;
Eric Andersen4ad13e52001-05-07 23:01:32 +000015
Eric Andersenc911a432001-05-15 17:42:16 +000016 lc = last_char_is(path, '/');
Eric Andersen4ad13e52001-05-07 23:01:32 +000017 if (filename[0] == '/')
18 filename++;
19 outbuf = xmalloc(strlen(path)+strlen(filename)+1+(lc==NULL));
20 sprintf(outbuf, (lc==NULL ? "%s/%s" : "%s%s"), path, filename);
Eric Andersene5dfced2001-04-09 22:48:12 +000021 return outbuf;
22}