diff options
author | Daniel Lezcano <daniel.lezcano@free.fr> | 2011-03-26 22:05:51 +0100 |
---|---|---|
committer | Amit Kucheria <amit.kucheria@linaro.org> | 2011-04-04 02:17:40 +0300 |
commit | 2e6ecca22703f0d539468712596ab73875bcbcd7 (patch) | |
tree | db543c1e77e4d0d529f710f8f52883396461e745 /regulator.c | |
parent | f28e488c601108992409821bf2c174a411348db5 (diff) |
browse /sys/class/regulator with a generic name
All the files found in the /sys/class/regulator directory should
be regulators. Don't assume their name begin with 'regulator'.
Signed-off-by: Daniel Lezcano <daniel.lezcano@free.fr>
Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
Diffstat (limited to 'regulator.c')
-rw-r--r-- | regulator.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/regulator.c b/regulator.c index 255a56d..342a1a7 100644 --- a/regulator.c +++ b/regulator.c @@ -15,20 +15,30 @@ #include "regulator.h" +#define SYSFS_REGULATOR "/sys/class/regulator" + int regulator_init(void) { DIR *regdir; struct dirent *item; - regdir = opendir("/sys/class/regulator"); - if (!regdir) - return(1); + regdir = opendir(SYSFS_REGULATOR); + if (!regdir) { + fprintf(stderr, "failed to open '%s': %m\n", SYSFS_REGULATOR); + return -1; + } + while ((item = readdir(regdir))) { - if (strncmp(item->d_name, "regulator", 9)) + + if (!strcmp(item->d_name, ".")) + continue; + + if (!strcmp(item->d_name, "..")) continue; numregulators++; } + closedir(regdir); regulators_info = (struct regulator_info *)malloc(numregulators* |