aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/helpers.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-06-10 22:29:58 -0700
committerChris Robinson <[email protected]>2019-06-10 22:29:58 -0700
commit97d56dd4243e1e16bef4e337e570022f170af118 (patch)
tree96a41d5c20fbca658953f333cd449d9e87f65a7b /Alc/helpers.cpp
parent1a14946306a29ce2a14bf3d3f536ab24100ada83 (diff)
Use C++ I/O to check for NEON support
Diffstat (limited to 'Alc/helpers.cpp')
-rw-r--r--Alc/helpers.cpp46
1 files changed, 18 insertions, 28 deletions
diff --git a/Alc/helpers.cpp b/Alc/helpers.cpp
index fb7addd3..9236e57a 100644
--- a/Alc/helpers.cpp
+++ b/Alc/helpers.cpp
@@ -206,45 +206,35 @@ void FillCPUCaps(int capfilter)
#endif
#endif
#ifdef HAVE_NEON
- FILE *file = fopen("/proc/cpuinfo", "rt");
- if(!file)
+ al::ifstream file{"/proc/cpuinfo"};
+ if(!file.is_open())
ERR("Failed to open /proc/cpuinfo, cannot check for NEON support\n");
else
{
std::string features;
- char buf[256];
- while(fgets(buf, sizeof(buf), file) != nullptr)
+ auto getline = [](std::istream &f, std::string &output) -> bool
{
- if(strncmp(buf, "Features\t:", 10) != 0)
- continue;
+ while(f.good() && f.peek() == '\n')
+ f.ignore();
+ return std::getline(f, output) && !output.empty();
- features = buf+10;
- while(features.back() != '\n')
- {
- if(fgets(buf, sizeof(buf), file) == nullptr)
- break;
- features += buf;
- }
- break;
+ };
+ while(getline(file, features))
+ {
+ if(features.compare(0, 10, "Features\t:", 10) == 0)
+ break;
}
- fclose(file);
- file = nullptr;
+ file.close();
- if(!features.empty())
+ size_t extpos{9};
+ while((extpos=features.find("neon", extpos+1)) != std::string::npos)
{
- const char *str = features.c_str();
- while(isspace(str[0])) ++str;
-
- TRACE("Got features string:%s\n", str);
- while((str=strstr(str, "neon")) != nullptr)
+ if((extpos == 0 || std::isspace(features[extpos-1])) &&
+ (extpos+4 == features.length() || std::isspace(features[extpos+4])))
{
- if(isspace(*(str-1)) && (str[4] == 0 || isspace(str[4])))
- {
- caps |= CPU_CAP_NEON;
- break;
- }
- ++str;
+ caps |= CPU_CAP_NEON;
+ break;
}
}
}