summaryrefslogtreecommitdiff
path: root/src/utils/dirname.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/dirname.cpp')
-rw-r--r--src/utils/dirname.cpp16
1 files changed, 16 insertions, 0 deletions
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 <utils/dirname.hpp>
+
+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);
+ }
+}