mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-29 16:44:03 +00:00
Improve separated_concat() to properly handle the case of concatenating
"/" and "/foo". MFC after: 1 month Sponsored by: The FreeBSD Foundation
This commit is contained in:
parent
1bc6f46438
commit
5585582d14
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=279807
@ -136,8 +136,14 @@ separated_concat(const char *s1, const char *s2, char separator)
|
||||
assert(s1 != NULL);
|
||||
assert(s2 != NULL);
|
||||
|
||||
if (s1[0] == '\0' || s2[0] == '\0' ||
|
||||
s1[strlen(s1) - 1] == separator || s2[0] == separator) {
|
||||
/*
|
||||
* If s2 starts with separator - skip it; otherwise concatenating
|
||||
* "/" and "/foo" would end up returning "//foo".
|
||||
*/
|
||||
if (s2[0] == separator)
|
||||
s2++;
|
||||
|
||||
if (s1[0] == '\0' || s2[0] == '\0' || s1[strlen(s1) - 1] == separator) {
|
||||
ret = asprintf(&result, "%s%s", s1, s2);
|
||||
} else {
|
||||
ret = asprintf(&result, "%s%c%s", s1, separator, s2);
|
||||
|
Loading…
Reference in New Issue
Block a user