return result;
}
-Path getcwd()
-{
- char buf[1024];
- return ::getcwd(buf, sizeof(buf));
-}
-
Path get_user_data_dir()
{
const string &name = Application::get_name();
return get_sys_lib_dir(argv0, Application::get_name());
}
-void chdir(const Path &path)
-{
- if(::chdir(path.str().c_str())==-1)
- throw system_error("chdir");
-}
-
Path path_lookup(const string &name, const list<Path> &paths)
{
for(list<Path>::const_iterator i=paths.begin(); i!=paths.end(); ++i)
/// Returns the current working directory
Path getcwd();
+/// Changes the current working directory
+void chdir(const Path &);
+
/// Returns the user's home directory
Path get_home_dir();
/// Returns a directory containing system-wide architecture-specific files.
Path get_sys_lib_dir();
-/// Changes the current working directory
-void chdir(const Path &);
-
/** Looks for a file in a list of paths. Returns the absolute path to the
first existing location, or an empty Path if the file is not found at all. */
Path path_lookup(const std::string &, const std::list<Path> &);
throw system_error("rmdir");
}
+Path getcwd()
+{
+ char buf[1024];
+ return ::getcwd(buf, sizeof(buf));
+}
+
+void chdir(const Path &path)
+{
+ if(::chdir(path.str().c_str())==-1)
+ throw system_error("chdir");
+}
+
Path get_home_dir()
{
const char *home = getenv("HOME");
#include <shlobj.h>
+#include <msp/core/mutex.h>
#include <msp/core/systemerror.h>
#include "dir.h"
throw system_error("RemoveDirectory");
}
+/* Windows documentation says Get/SetCurrentDirectory use a global buffer and
+are not thread safe. */
+static Mutex &cwd_mutex()
+{
+ static Mutex mutex;
+ return mutex;
+}
+
+Path getcwd()
+{
+ MutexLock lock(cwd_mutex());
+
+ char buf[1024];
+ Path result;
+ DWORD len = GetCurrentDirectory(sizeof(buf), buf);
+ if(len>=sizeof(buf))
+ {
+ vector<char> buf2(len+1);
+ len = GetCurrentDirectory(buf2.size(), buf2.data());
+ result = buf2.data();
+ }
+ else
+ result = buf;
+
+ if(!len)
+ throw system_error("GetCurrentDirectory");
+
+ return result;
+}
+
+void chdir(const Path &path)
+{
+ MutexLock lock(cwd_mutex());
+ if(!SetCurrentDirectory(path.c_str()))
+ throw system_error("SetCurrentDirectory");
+}
+
Path get_home_dir()
{
char home[MAX_PATH];