summaryrefslogtreecommitdiff
path: root/libbb/concat_path_file.c
diff options
context:
space:
mode:
authorEric Andersen2001-05-07 23:01:32 +0000
committerEric Andersen2001-05-07 23:01:32 +0000
commit4ad13e5d957ae85b3a6a61fce7b58a661adb2b1c (patch)
treeb8225e58934a043ec30eb2908269c6987324cd58 /libbb/concat_path_file.c
parentc33ebc9741a475962e29fafe60bb0ba4450854b6 (diff)
downloadbusybox-4ad13e5d957ae85b3a6a61fce7b58a661adb2b1c.zip
busybox-4ad13e5d957ae85b3a6a61fce7b58a661adb2b1c.tar.gz
A patch from Vladimir to simplify concat_path_file() and
make it less likely to break.
Diffstat (limited to 'libbb/concat_path_file.c')
-rw-r--r--libbb/concat_path_file.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/libbb/concat_path_file.c b/libbb/concat_path_file.c
index ce92310..6b7abf2 100644
--- a/libbb/concat_path_file.c
+++ b/libbb/concat_path_file.c
@@ -11,16 +11,12 @@
extern char *concat_path_file(const char *path, const char *filename)
{
char *outbuf;
- int l;
- int flg_slash = 1;
-
- l = strlen(path);
- if (l>0 && path[l-1] == '/')
- flg_slash--;
- l += strlen(filename);
- if (l>0 && filename[0] == '/')
- flg_slash--;
- outbuf = xmalloc(l+1+flg_slash);
- sprintf(outbuf, (flg_slash ? "%s/%s" : "%s%s"), path, filename);
+ const char *lc;
+
+ lc = last_char_is((char*)path, '/');
+ if (filename[0] == '/')
+ filename++;
+ outbuf = xmalloc(strlen(path)+strlen(filename)+1+(lc==NULL));
+ sprintf(outbuf, (lc==NULL ? "%s/%s" : "%s%s"), path, filename);
return outbuf;
}