diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-04-26 11:31:16 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-04-26 12:15:00 -0400 |
commit | 4bd112df3eea4db63fe90fb4e83c48d3f3bd6512 (patch) | |
tree | ec7db18635dd1db653271c0dd620af240e1384f4 /tools/lib/api | |
parent | ccd9b2a7f82b069b8e8ac892fd9c1c22e7b11eba (diff) |
tools lib api fs: Add helper to read string from procfs file
To read things like /proc/self/comm.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Milian Wolff <milian.wolff@kdab.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-ztpkbmseidt0hq2psr46o0h9@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib/api')
-rw-r--r-- | tools/lib/api/fs/fs.c | 13 | ||||
-rw-r--r-- | tools/lib/api/fs/fs.h | 2 |
2 files changed, 15 insertions, 0 deletions
diff --git a/tools/lib/api/fs/fs.c b/tools/lib/api/fs/fs.c index ef78c22ff44d..08556cf2c70d 100644 --- a/tools/lib/api/fs/fs.c +++ b/tools/lib/api/fs/fs.c | |||
@@ -351,6 +351,19 @@ int filename__read_str(const char *filename, char **buf, size_t *sizep) | |||
351 | return err; | 351 | return err; |
352 | } | 352 | } |
353 | 353 | ||
354 | int procfs__read_str(const char *entry, char **buf, size_t *sizep) | ||
355 | { | ||
356 | char path[PATH_MAX]; | ||
357 | const char *procfs = procfs__mountpoint(); | ||
358 | |||
359 | if (!procfs) | ||
360 | return -1; | ||
361 | |||
362 | snprintf(path, sizeof(path), "%s/%s", procfs, entry); | ||
363 | |||
364 | return filename__read_str(path, buf, sizep); | ||
365 | } | ||
366 | |||
354 | int sysfs__read_ull(const char *entry, unsigned long long *value) | 367 | int sysfs__read_ull(const char *entry, unsigned long long *value) |
355 | { | 368 | { |
356 | char path[PATH_MAX]; | 369 | char path[PATH_MAX]; |
diff --git a/tools/lib/api/fs/fs.h b/tools/lib/api/fs/fs.h index 9f6598098dc5..16c9c2ed7c5b 100644 --- a/tools/lib/api/fs/fs.h +++ b/tools/lib/api/fs/fs.h | |||
@@ -29,6 +29,8 @@ int filename__read_int(const char *filename, int *value); | |||
29 | int filename__read_ull(const char *filename, unsigned long long *value); | 29 | int filename__read_ull(const char *filename, unsigned long long *value); |
30 | int filename__read_str(const char *filename, char **buf, size_t *sizep); | 30 | int filename__read_str(const char *filename, char **buf, size_t *sizep); |
31 | 31 | ||
32 | int procfs__read_str(const char *entry, char **buf, size_t *sizep); | ||
33 | |||
32 | int sysctl__read_int(const char *sysctl, int *value); | 34 | int sysctl__read_int(const char *sysctl, int *value); |
33 | int sysfs__read_int(const char *entry, int *value); | 35 | int sysfs__read_int(const char *entry, int *value); |
34 | int sysfs__read_ull(const char *entry, unsigned long long *value); | 36 | int sysfs__read_ull(const char *entry, unsigned long long *value); |