find_file: automatically add missing '/' and end of paths
This commit is contained in:
parent
17f7607a30
commit
4069f42845
|
@ -187,9 +187,11 @@ void write_buffer_to_file(const Buffer& buffer, const String& filename)
|
||||||
|
|
||||||
String find_file(const String& filename, const memoryview<String>& paths)
|
String find_file(const String& filename, const memoryview<String>& paths)
|
||||||
{
|
{
|
||||||
for (auto path : paths)
|
for (auto candidate : paths)
|
||||||
{
|
{
|
||||||
String candidate = path + filename;
|
if (not candidate.empty() and candidate.back() != '/')
|
||||||
|
candidate += '/';
|
||||||
|
candidate += filename;
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
if (stat(candidate.c_str(), &buf) == 0 and S_ISREG(buf.st_mode))
|
if (stat(candidate.c_str(), &buf) == 0 and S_ISREG(buf.st_mode))
|
||||||
return candidate;
|
return candidate;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user