aboutsummaryrefslogtreecommitdiffstats
path: root/alc/helpers.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2021-02-27 13:09:43 -0800
committerChris Robinson <[email protected]>2021-02-27 13:09:43 -0800
commit4179633440cbe418174c8d4a0c359f337995a394 (patch)
treedf396aeb0d08a7b861a0b8d22cda57346994b175 /alc/helpers.cpp
parent6e676b81d588f9bfd2b0b69af48cdf9a701ca24a (diff)
Avoid calling readlink on platforms that don't support it
Also don't keep trying to find the path+name if it fails the first time.
Diffstat (limited to 'alc/helpers.cpp')
-rw-r--r--alc/helpers.cpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/alc/helpers.cpp b/alc/helpers.cpp
index 8c1c8562..fe967f7f 100644
--- a/alc/helpers.cpp
+++ b/alc/helpers.cpp
@@ -205,9 +205,8 @@ void SetRTPriority(void)
const PathNamePair &GetProcBinary()
{
- static PathNamePair ret;
- if(!ret.fname.empty() || !ret.path.empty())
- return ret;
+ static al::optional<PathNamePair> procbin;
+ if(procbin) return *procbin;
al::vector<char> pathname;
#ifdef __FreeBSD__
@@ -241,6 +240,7 @@ const PathNamePair &GetProcBinary()
pathname.insert(pathname.end(), procpath, procpath+strlen(procpath));
}
#endif
+#ifndef __SWITCH__
if(pathname.empty())
{
static const char SelfLinkNames[][32]{
@@ -269,25 +269,25 @@ const PathNamePair &GetProcBinary()
if(len <= 0)
{
WARN("Failed to readlink %s: %s\n", selfname, strerror(errno));
- return ret;
+ len = 0;
}
pathname.resize(static_cast<size_t>(len));
}
+#endif
while(!pathname.empty() && pathname.back() == 0)
pathname.pop_back();
auto sep = std::find(pathname.crbegin(), pathname.crend(), '/');
if(sep != pathname.crend())
- {
- ret.path = std::string(pathname.cbegin(), sep.base()-1);
- ret.fname = std::string(sep.base(), pathname.cend());
- }
+ procbin = al::make_optional<PathNamePair>(std::string(pathname.cbegin(), sep.base()-1),
+ std::string(sep.base(), pathname.cend()));
else
- ret.fname = std::string(pathname.cbegin(), pathname.cend());
+ procbin = al::make_optional<PathNamePair>(std::string{},
+ std::string(pathname.cbegin(), pathname.cend()));
- TRACE("Got binary: %s, %s\n", ret.path.c_str(), ret.fname.c_str());
- return ret;
+ TRACE("Got binary: \"%s\", \"%s\"\n", procbin->path.c_str(), procbin->fname.c_str());
+ return *procbin;
}
namespace {