]> git.tdb.fi Git - libs/core.git/blobdiff - source/fs/dir.cpp
Add wrappers for environment manipulation functions
[libs/core.git] / source / fs / dir.cpp
index 098020328342db2edf93d4b2b425555405ab5f00..218a7a5cf75e0b8a1a05576bf4d5893423f02ec9 100644 (file)
@@ -1,7 +1,6 @@
-#include <cstdlib>
-#include <unistd.h>
 #include <dirent.h>
 #include <msp/core/application.h>
+#include <msp/core/environ.h>
 #include <msp/core/systemerror.h>
 #include <msp/strings/regex.h>
 #include <msp/strings/utils.h>
@@ -38,7 +37,9 @@ const Path &get_bin_dir(const string &argv0)
        {
                Path exe;
                if(argv0.find(DIRSEP)==string::npos)
-                       if(const char *path = getenv("PATH"))
+               {
+                       string path = getenv("PATH");
+                       if(!path.empty())
                        {
                                for(const string &d: split(path, ITEMSEP))
                                        if(exists(Path(d)/argv0))
@@ -47,6 +48,7 @@ const Path &get_bin_dir(const string &argv0)
                                                break;
                                        }
                        }
+               }
 
                if(exe.empty())
                        exe = realpath(argv0);
@@ -191,7 +193,7 @@ Path path_lookup(const string &name, const vector<Path> &paths)
 
 Path path_lookup(const string &name)
 {
-       const char *path = getenv("PATH");
+       string path = getenv("PATH");
        vector<string> dirs = split(path, ITEMSEP);
        return path_lookup(name, vector<Path>(dirs.begin(), dirs.end()));
 }