diff options
author | Daniel Lezcano <daniel.lezcano@linaro.org> | 2011-06-15 15:45:12 +0200 |
---|---|---|
committer | Daniel Lezcano <daniel.lezcano@linaro.org> | 2011-06-15 15:45:12 +0200 |
commit | 88b38e388fc20499eff99bb7282fccdb481f8828 (patch) | |
tree | 932f3b9100be2bf3413b229d9a8a8a5902f374a1 /clocks.c | |
parent | 05916f88daf6dae6185f4ec5792b7ceb552cf8fc (diff) | |
download | powerdebug-88b38e388fc20499eff99bb7282fccdb481f8828.tar.gz |
Add some helper functions in a specific utils file
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Diffstat (limited to 'clocks.c')
-rw-r--r-- | clocks.c | 62 |
1 files changed, 1 insertions, 61 deletions
@@ -28,6 +28,7 @@ #include "powerdebug.h" #include "clocks.h" #include "tree.h" +#include "utils.h" struct clock_info { int flags; @@ -75,67 +76,6 @@ static struct clock_info *clock_alloc(void) return ci; } -/* - * This functions is a helper to read a specific file content and store - * the content inside a variable pointer passed as parameter, the format - * parameter gives the variable type to be read from the file. - * - * @path : directory path containing the file - * @name : name of the file to be read - * @format : the format of the format - * @value : a pointer to a variable to store the content of the file - * Returns 0 on success, -1 otherwise - */ -int file_read_value(const char *path, const char *name, - const char *format, void *value) -{ - FILE *file; - char *rpath; - int ret; - - ret = asprintf(&rpath, "%s/%s", path, name); - if (ret < 0) - return ret; - - file = fopen(rpath, "r"); - if (!file) { - ret = -1; - goto out_free; - } - - ret = fscanf(file, format, value) == EOF ? -1 : 0; - - fclose(file); -out_free: - free(rpath); - return ret; -} - -static int file_read_from_format(const char *file, int *value, - const char *format) -{ - FILE *f; - int ret; - - f = fopen(file, "r"); - if (!f) - return -1; - ret = fscanf(f, format, value); - fclose(f); - - return !ret ? -1 : 0; -} - -static inline int file_read_int(const char *file, int *value) -{ - return file_read_from_format(file, value, "%d"); -} - -static inline int file_read_hex(const char *file, int *value) -{ - return file_read_from_format(file, value, "%x"); -} - static inline const char *clock_rate(int *rate) { int r; |