Skip to content

Commit

Permalink
[MeterW1therm] avoid GLOB_BRACE, don't require glibc
Browse files Browse the repository at this point in the history
  • Loading branch information
r00t- committed Mar 31, 2021
1 parent d4a0c9b commit 677b02a
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/protocols/MeterW1therm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,22 @@ bool MeterW1therm::W1sysHWif::scanW1devices() {
// let's try using glob()
glob_t glob_res;
size_t strl = strlen("/sys/bus/w1/devices/");
if (0 ==
glob("/sys/bus/w1/devices/{10,22,28,3b,42}-*", GLOB_BRACE | GLOB_NOSORT, NULL, &glob_res)) {
if (0 == glob("/sys/bus/w1/devices/"
"?"
"?"
"-*",
GLOB_NOSORT, NULL, &glob_res)) {

// 1wire ID prefixes of supported sensors
const char *ids[] = {"10", "22", "28", "3b", "42", NULL};

for (unsigned int i = 0; i < glob_res.gl_pathc; ++i) {
if (strlen(glob_res.gl_pathv[i]) > strl) {
char *str = glob_res.gl_pathv[i] + strl;
_devices.push_back(std::string(str));
for (unsigned int j = 0; ids[j] != NULL; j++) {
if (strlen(glob_res.gl_pathv[i]) > strl &&
!strncmp(glob_res.gl_pathv[i] + strl, ids[j], 2)) {
char *str = glob_res.gl_pathv[i] + strl;
_devices.push_back(std::string(str));
}
}
}

Expand Down

0 comments on commit 677b02a

Please sign in to comment.