- if(appname.empty())
- throw invalid_argument("get_user_data_dir");
- char datadir[MAX_PATH];
- if(SHGetFolderPath(0, CSIDL_LOCAL_APPDATA, 0, 0, datadir)==S_OK)
- return Path(datadir)/appname;
- return ".";
+ 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");