Skip to content

Commit fe5698d

Browse files
authored
Make append_path in host utils a simple concatenation (#117392)
1 parent 1fb5178 commit fe5698d

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/native/corehost/hostmisc/utils.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,21 @@ bool utils::ends_with(const pal::string_t& value, const pal::char_t* suffix, siz
5252

5353
void append_path(pal::string_t* path1, const pal::char_t* path2)
5454
{
55-
if (pal::is_path_rooted(path2))
55+
if (pal::strlen(path2) == 0)
56+
return;
57+
58+
if (path1->empty())
5659
{
5760
path1->assign(path2);
61+
return;
5862
}
59-
else
63+
64+
if (path1->back() != DIR_SEPARATOR && path2[0] != DIR_SEPARATOR)
6065
{
61-
if (!path1->empty() && path1->back() != DIR_SEPARATOR)
62-
{
63-
path1->push_back(DIR_SEPARATOR);
64-
}
65-
path1->append(path2);
66+
path1->push_back(DIR_SEPARATOR);
6667
}
68+
69+
path1->append(path2);
6770
}
6871

6972
pal::string_t strip_executable_ext(const pal::string_t& filename)

src/native/corehost/hostmisc/utils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ pal::string_t get_directory(const pal::string_t& path);
7676
pal::string_t strip_file_ext(const pal::string_t& path);
7777
pal::string_t get_filename(const pal::string_t& path);
7878
pal::string_t get_filename_without_ext(const pal::string_t& path);
79+
80+
// Concatenate path1 and path2 into path1, ensuring there is a directory separator.
81+
// This does not check for rooted paths or make any attempt to root the returned path.
7982
void append_path(pal::string_t* path1, const pal::char_t* path2);
83+
8084
bool file_exists_in_dir(const pal::string_t& dir, const pal::char_t* file_name, pal::string_t* out_file_path);
8185
bool coreclr_exists_in_dir(const pal::string_t& candidate);
8286
void remove_trailing_dir_separator(pal::string_t* dir);

0 commit comments

Comments
 (0)