blob: 61efa9c3e16ac7ab13fdbe3f8ec0125c727425e1 [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 Andersen4ad13e52001-05-07 23:01:32 +000016
Eric Andersenc911a432001-05-15 17:42:16 +000017 lc = last_char_is(path, '/');
Eric Andersen4ad13e52001-05-07 23:01:32 +000018 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);
Eric Andersene5dfced2001-04-09 22:48:12 +000022 return outbuf;
23}