Cache the process binary path and name

This commit is contained in:
Chris Robinson
2018-12-25 11:27:22 -08:00
parent 208ea76922
commit 0314370eb5
4 changed files with 22 additions and 18 deletions
+11 -11
View File
@@ -299,12 +299,12 @@ void ReadALConfig(void) noexcept
LoadConfigFromFile(f);
}
PathNamePair ppath = GetProcBinary();
if(!ppath.path.empty())
std::string ppath{GetProcBinary().path};
if(!ppath.empty())
{
ppath.path += "\\alsoft.ini";
TRACE("Loading config %s...\n", ppath.path.c_str());
al::ifstream f{ppath.path.c_str()};
ppath += "\\alsoft.ini";
TRACE("Loading config %s...\n", ppath.c_str());
al::ifstream f{ppath};
if(f.is_open())
LoadConfigFromFile(f);
}
@@ -422,14 +422,14 @@ void ReadALConfig(void) noexcept
LoadConfigFromFile(f);
}
PathNamePair ppath = GetProcBinary();
if(!ppath.path.empty())
std::string ppath{GetProcBinary().path};
if(!ppath.empty())
{
if(ppath.path.back() != '/') ppath.path += "/alsoft.conf";
else ppath.path += "alsoft.conf";
if(ppath.back() != '/') ppath += "/alsoft.conf";
else ppath += "alsoft.conf";
TRACE("Loading config %s...\n", ppath.path.c_str());
al::ifstream f{ppath.path};
TRACE("Loading config %s...\n", ppath.c_str());
al::ifstream f{ppath};
if(f.is_open())
LoadConfigFromFile(f);
}
+1 -1
View File
@@ -406,7 +406,7 @@ pa_context *connect_context(pa_threaded_mainloop *loop, ALboolean silent)
{
const char *name{"OpenAL Soft"};
PathNamePair binname = GetProcBinary();
const PathNamePair &binname = GetProcBinary();
if(!binname.fname.empty())
name = binname.fname.c_str();
+1 -1
View File
@@ -223,7 +223,7 @@ using ifstream = std::ifstream;
#include <string>
struct PathNamePair { std::string path, fname; };
PathNamePair GetProcBinary(void);
const PathNamePair &GetProcBinary(void);
#ifdef HAVE_DYNLOAD
void *LoadLib(const char *name);
+9 -5
View File
@@ -310,9 +310,11 @@ void FPUCtl::leave() noexcept
#ifdef _WIN32
PathNamePair GetProcBinary()
const PathNamePair &GetProcBinary()
{
PathNamePair ret;
static PathNamePair ret;
if(!ret.fname.empty() || !ret.path.empty())
return ret;
al::vector<WCHAR> fullpath(256);
DWORD len;
@@ -477,11 +479,13 @@ void SetRTPriority(void)
#else
PathNamePair GetProcBinary()
const PathNamePair &GetProcBinary()
{
PathNamePair ret;
al::vector<char> pathname;
static PathNamePair ret;
if(!ret.fname.empty() || !ret.path.empty())
return ret;
al::vector<char> pathname;
#ifdef __FreeBSD__
size_t pathlen;
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };