From d95718ed6f71d7dcfdaaab39201129250fb8c222 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 23 Oct 2022 19:11:14 +0000 Subject: [PATCH] ircd::fs: Additional convenience tools for path suite. --- include/ircd/fs/path.h | 4 ++++ ircd/fs_path.cc | 23 ++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/include/ircd/fs/path.h b/include/ircd/fs/path.h index 9e3e7c149..c83cb0dd0 100644 --- a/include/ircd/fs/path.h +++ b/include/ircd/fs/path.h @@ -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 diff --git a/ircd/fs_path.cc b/ircd/fs_path.cc index 1278218f1..aba43bb21 100644 --- a/ircd/fs_path.cc +++ b/ircd/fs_path.cc @@ -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)