From 7b3e0e0cf3eddd3537455a3605b04a48ee663f47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sun, 30 Apr 2017 15:04:40 +0200 Subject: =?UTF-8?q?Make=20botan=E2=80=99s=20policy=20configurable=20from?= =?UTF-8?q?=20a=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #3244 --- src/utils/dirname.cpp | 16 ++++++++++++++++ src/utils/dirname.hpp | 6 ++++++ src/utils/xdg.hpp | 2 -- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/utils/dirname.cpp create mode 100644 src/utils/dirname.hpp (limited to 'src/utils') diff --git a/src/utils/dirname.cpp b/src/utils/dirname.cpp new file mode 100644 index 0000000..71c9c38 --- /dev/null +++ b/src/utils/dirname.cpp @@ -0,0 +1,16 @@ +#include + +namespace utils +{ + std::string dirname(const std::string filename) + { + if (filename.empty()) + return "./"; + if (filename == ".." || filename == ".") + return filename; + auto pos = filename.rfind('/'); + if (pos == std::string::npos) + return "./"; + return filename.substr(0, pos + 1); + } +} diff --git a/src/utils/dirname.hpp b/src/utils/dirname.hpp new file mode 100644 index 0000000..c1df81b --- /dev/null +++ b/src/utils/dirname.hpp @@ -0,0 +1,6 @@ +#include + +namespace utils +{ +std::string dirname(const std::string filename); +} diff --git a/src/utils/xdg.hpp b/src/utils/xdg.hpp index 56e11da..7be6922 100644 --- a/src/utils/xdg.hpp +++ b/src/utils/xdg.hpp @@ -10,5 +10,3 @@ */ std::string xdg_config_path(const std::string& filename); std::string xdg_data_path(const std::string& filename); - - -- cgit v1.2.3