Implement suggestion from Adam Slattery, (don't default to killing closing bug #1190.
[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         lc = last_char_is(path, '/');
18         if (filename[0] == '/')
19                 filename++;
20         outbuf = xmalloc(strlen(path)+strlen(filename)+1+(lc==NULL));
21         sprintf(outbuf, (lc==NULL ? "%s/%s" : "%s%s"), path, filename);
22         return outbuf;
23 }