ircd::fs: Additional convenience tools for path suite.

This commit is contained in:
Jason Volk 2022-10-23 19:11:14 +00:00
parent 561be9973a
commit d95718ed6f
2 changed files with 26 additions and 1 deletions

View File

@ -67,6 +67,10 @@ namespace ircd::fs
string_view canonical(const mutable_buffer &, const string_view &root, const string_view &path);
string_view relative(const mutable_buffer &, const string_view &root, const string_view &path);
string_view absolute(const mutable_buffer &, const string_view &root, const string_view &path);
bool is_extension(const string_view &path, const string_view &str);
bool is_filename(const string_view &path, const string_view &str);
bool is_parent(const string_view &path, const string_view &str);
}
/// Configuration items storing the base paths used at runtime for program

View File

@ -42,7 +42,7 @@ ircd::fs::PATH_MAX_LEN
namespace ircd::fs
{
static thread_local char _name_scratch[2][NAME_MAX_LEN];
static thread_local char _path_scratch[2][PATH_MAX_LEN];
static thread_local char _path_scratch[3][PATH_MAX_LEN];
}
// External mutable_buffer to the scratch
@ -233,6 +233,27 @@ ircd::fs::base::db
// tools
//
bool
ircd::fs::is_parent(const string_view &path,
const string_view &str)
{
return parent(_path_scratch[2], path) == str;
}
bool
ircd::fs::is_filename(const string_view &path,
const string_view &str)
{
return filename(_path_scratch[2], path) == str;
}
bool
ircd::fs::is_extension(const string_view &path,
const string_view &str)
{
return extension(_path_scratch[2], path) == str;
}
ircd::string_view
ircd::fs::canonical(const mutable_buffer &buf,
const string_view &p)