diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-05-07 23:01:32 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-05-07 23:01:32 +0000 |
commit | 4ad13e5d957ae85b3a6a61fce7b58a661adb2b1c (patch) | |
tree | b8225e58934a043ec30eb2908269c6987324cd58 /libbb/concat_path_file.c | |
parent | c33ebc9741a475962e29fafe60bb0ba4450854b6 (diff) | |
download | busybox-w32-4ad13e5d957ae85b3a6a61fce7b58a661adb2b1c.tar.gz busybox-w32-4ad13e5d957ae85b3a6a61fce7b58a661adb2b1c.tar.bz2 busybox-w32-4ad13e5d957ae85b3a6a61fce7b58a661adb2b1c.zip |
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.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/libbb/concat_path_file.c b/libbb/concat_path_file.c index ce92310ea..6b7abf24b 100644 --- a/libbb/concat_path_file.c +++ b/libbb/concat_path_file.c | |||
@@ -11,16 +11,12 @@ | |||
11 | extern char *concat_path_file(const char *path, const char *filename) | 11 | extern char *concat_path_file(const char *path, const char *filename) |
12 | { | 12 | { |
13 | char *outbuf; | 13 | char *outbuf; |
14 | int l; | 14 | const char *lc; |
15 | int flg_slash = 1; | 15 | |
16 | 16 | lc = last_char_is((char*)path, '/'); | |
17 | l = strlen(path); | 17 | if (filename[0] == '/') |
18 | if (l>0 && path[l-1] == '/') | 18 | filename++; |
19 | flg_slash--; | 19 | outbuf = xmalloc(strlen(path)+strlen(filename)+1+(lc==NULL)); |
20 | l += strlen(filename); | 20 | sprintf(outbuf, (lc==NULL ? "%s/%s" : "%s%s"), path, filename); |
21 | if (l>0 && filename[0] == '/') | ||
22 | flg_slash--; | ||
23 | outbuf = xmalloc(l+1+flg_slash); | ||
24 | sprintf(outbuf, (flg_slash ? "%s/%s" : "%s%s"), path, filename); | ||
25 | return outbuf; | 21 | return outbuf; |
26 | } | 22 | } |