86dd2fbbf8678feac063a31e5f91d100cc1881e4
[oweals/busybox.git] / libbb / concat_path_file.c
1 /*
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 <string.h>
10 #include "libbb.h"
11
12 extern char *concat_path_file(const char *path, const char *filename)
13 {
14         char *outbuf;
15         char *lc;
16
17         if (!path)
18             path="";
19         lc = last_char_is(path, '/');
20         while (*filename == '/')
21                 filename++;
22         outbuf = xmalloc(strlen(path)+strlen(filename)+1+(lc==NULL));
23         sprintf(outbuf, "%s%s%s", path, (lc==NULL)? "/" : "", filename);
24
25         return outbuf;
26 }