summaryrefslogtreecommitdiffstats
path: root/tools/lib/api/fs/fs.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2016-04-26 17:31:16 +0200
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-04-26 18:15:00 +0200
commit4bd112df3eea4db63fe90fb4e83c48d3f3bd6512 (patch)
treeec7db18635dd1db653271c0dd620af240e1384f4 /tools/lib/api/fs/fs.c
parentperf trace: Do not beautify the 'pid' parameter as a simple integer (diff)
downloadlinux-4bd112df3eea4db63fe90fb4e83c48d3f3bd6512.tar.xz
linux-4bd112df3eea4db63fe90fb4e83c48d3f3bd6512.zip
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/fs/fs.c')
-rw-r--r--tools/lib/api/fs/fs.c13
1 files changed, 13 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)
return err;
}
+int procfs__read_str(const char *entry, char **buf, size_t *sizep)
+{
+ char path[PATH_MAX];
+ const char *procfs = procfs__mountpoint();
+
+ if (!procfs)
+ return -1;
+
+ snprintf(path, sizeof(path), "%s/%s", procfs, entry);
+
+ return filename__read_str(path, buf, sizep);
+}
+
int sysfs__read_ull(const char *entry, unsigned long long *value)
{
char path[PATH_MAX];