diff options
author | Daniel Black <daniel.black@au1.ibm.com> | 2016-05-23 11:39:11 +1000 |
---|---|---|
committer | Nivedita Swaminathan <nivedita.swaminathan@intel.com> | 2016-07-21 15:12:34 -0700 |
commit | 351f7f02125bee2799fcccf4541a0a9c66a55a96 (patch) | |
tree | a1aa4c3929b2bf4ec9e8cd00dac681cb04a09cff | |
parent | 764401dc341ea81c6ad1b48b206d1e37b011679a (diff) | |
download | powertop-2.0-351f7f02125bee2799fcccf4541a0a9c66a55a96.tar.gz |
Add process_glob similar to process_directory.
This enables a glob to be specified to grab sysfs files in
subdirectories for setting up measurement or anything else
the callback function does.
-rw-r--r-- | src/lib.cpp | 27 | ||||
-rw-r--r-- | src/lib.h | 1 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/lib.cpp b/src/lib.cpp index 56e1681..cdbd0cd 100644 --- a/src/lib.cpp +++ b/src/lib.cpp @@ -58,6 +58,7 @@ extern "C" { #include <math.h> #include <ncurses.h> #include <fcntl.h> +#include <glob.h> static int kallsyms_read = 0; @@ -456,6 +457,32 @@ void process_directory(const char *d_name, callback fn) closedir(dir); } +void process_glob(const char *d_glob, callback fn) +{ + glob_t g; + size_t c; + + switch (glob(d_glob, GLOB_ERR | GLOB_MARK | GLOB_NOSORT, NULL, &g)) { + case GLOB_NOSPACE: + fprintf(stderr,_("glob returned GLOB_NOSPACE\n")); + globfree(&g); + return; + case GLOB_ABORTED: + fprintf(stderr,_("glob returned GLOB_ABORTED\n")); + globfree(&g); + return; + case GLOB_NOMATCH: + fprintf(stderr,_("glob returned GLOB_NOMATCH\n")); + globfree(&g); + return; + } + + for (c=0; c < g.gl_pathc; c++) { + fn(g.gl_pathv[c]); + } + globfree(&g); +} + int get_user_input(char *buf, unsigned sz) { fflush(stdout); @@ -84,6 +84,7 @@ template<size_t N> void pt_strcpy(char (&d)[N], const char *s) typedef void (*callback)(const char*); extern void process_directory(const char *d_name, callback fn); +extern void process_glob(const char *glob, callback fn); extern int utf_ok; extern int get_user_input(char *buf, unsigned sz); extern int read_msr(int cpu, uint64_t offset, uint64_t *value); |