summaryrefslogtreecommitdiff
path: root/src/support/path.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/support/path.cpp')
-rw-r--r--src/support/path.cpp31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/support/path.cpp b/src/support/path.cpp
index e9817aca9..2501c636c 100644
--- a/src/support/path.cpp
+++ b/src/support/path.cpp
@@ -24,16 +24,32 @@ namespace wasm {
namespace Path {
-std::string getPathSeparator() {
+char getPathSeparator() {
// TODO: use c++17's path separator
// http://en.cppreference.com/w/cpp/experimental/fs/path
#if defined(WIN32) || defined(_WIN32)
- return "\\";
+ return '\\';
#else
- return "/";
+ return '/';
#endif
}
+std::string getDirName(const std::string& path) {
+ auto sep = path.rfind(getPathSeparator());
+ if (sep == std::string::npos) {
+ return "";
+ }
+ return path.substr(0, sep);
+}
+
+std::string getBaseName(const std::string& path) {
+ auto sep = path.rfind(getPathSeparator());
+ if (sep == std::string::npos) {
+ return path;
+ }
+ return path.substr(sep + 1);
+}
+
std::string getBinaryenRoot() {
auto* envVar = getenv("BINARYEN_ROOT");
if (envVar) {
@@ -52,10 +68,15 @@ std::string getBinaryenBinDir() {
}
}
-void setBinaryenBinDir(std::string dir) { binDir = dir; }
+void setBinaryenBinDir(const std::string& dir) {
+ binDir = dir;
+ if (binDir.back() != getPathSeparator()) {
+ binDir += getPathSeparator();
+ }
+}
// Gets the path to a binaryen binary tool, like wasm-opt
-std::string getBinaryenBinaryTool(std::string name) {
+std::string getBinaryenBinaryTool(const std::string& name) {
return getBinaryenBinDir() + name;
}