Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1333509
| From | Jiri Olsa <jolsa@kernel.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 3/5] tools lib api fs: Add sysfs__read_str function |
| Date | 2016-02-14 17:10 +0100 |
| Message-ID | <r27pg-4Un-13@gated-at.bofh.it> (permalink) |
| References | <r27pg-4Un-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Adding sysfs__read_str function to ease up reading
string files from sysfs. New interface is:
int sysfs__read_str(const char *entry, char **buf, size_t *sizep);
Link: http://lkml.kernel.org/n/tip-em9nb2r0dnbggdxrnyf6wnb9@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
tools/lib/api/fs/fs.c | 13 +++++++++++++
tools/lib/api/fs/fs.h | 1 +
2 files changed, 14 insertions(+)
diff --git a/tools/lib/api/fs/fs.c b/tools/lib/api/fs/fs.c
index 2cbf6773ca5d..ef78c22ff44d 100644
--- a/tools/lib/api/fs/fs.c
+++ b/tools/lib/api/fs/fs.c
@@ -377,6 +377,19 @@ int sysfs__read_int(const char *entry, int *value)
return filename__read_int(path, value);
}
+int sysfs__read_str(const char *entry, char **buf, size_t *sizep)
+{
+ char path[PATH_MAX];
+ const char *sysfs = sysfs__mountpoint();
+
+ if (!sysfs)
+ return -1;
+
+ snprintf(path, sizeof(path), "%s/%s", sysfs, entry);
+
+ return filename__read_str(path, buf, sizep);
+}
+
int sysctl__read_int(const char *sysctl, int *value)
{
char path[PATH_MAX];
diff --git a/tools/lib/api/fs/fs.h b/tools/lib/api/fs/fs.h
index 858922b61141..9f6598098dc5 100644
--- a/tools/lib/api/fs/fs.h
+++ b/tools/lib/api/fs/fs.h
@@ -32,4 +32,5 @@ int filename__read_str(const char *filename, char **buf, size_t *sizep);
int sysctl__read_int(const char *sysctl, int *value);
int sysfs__read_int(const char *entry, int *value);
int sysfs__read_ull(const char *entry, unsigned long long *value);
+int sysfs__read_str(const char *entry, char **buf, size_t *sizep);
#endif /* __API_FS__ */
--
2.4.3
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 0/5] perf tools: Store CPU cache details under perf data Jiri Olsa <jolsa@kernel.org> - 2016-02-14 17:10 +0100
[PATCH 3/5] tools lib api fs: Add sysfs__read_str function Jiri Olsa <jolsa@kernel.org> - 2016-02-14 17:10 +0100
[tip:perf/core] tools lib api fs: Add sysfs__read_str function tip-bot for Jiri Olsa <tipbot@zytor.com> - 2016-02-17 13:10 +0100
[PATCH 5/5] perf tools: Add perf data cache feature Jiri Olsa <jolsa@kernel.org> - 2016-02-14 17:10 +0100
[PATCHv2 5/5] perf tools: Add perf data cache feature Jiri Olsa <jolsa@redhat.com> - 2016-02-16 13:20 +0100
Re: [PATCHv2 5/5] perf tools: Add perf data cache feature Namhyung Kim <namhyung@kernel.org> - 2016-02-16 15:30 +0100
[PATCHv3 5/5] perf tools: Add perf data cache feature Jiri Olsa <jolsa@redhat.com> - 2016-02-16 16:10 +0100
Re: [PATCHv3 5/5] perf tools: Add perf data cache feature Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-02-16 16:30 +0100
Re: [PATCHv3 5/5] perf tools: Add perf data cache feature Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com> - 2016-02-16 16:50 +0100
[tip:perf/core] perf tools: Add perf data cache feature tip-bot for Jiri Olsa <tipbot@zytor.com> - 2016-02-17 13:10 +0100
[PATCH 4/5] perf tools: Initialize libapi debug output Jiri Olsa <jolsa@kernel.org> - 2016-02-14 17:10 +0100
[tip:perf/core] perf tools: Initialize libapi debug output tip-bot for Jiri Olsa <tipbot@zytor.com> - 2016-02-17 13:10 +0100
[PATCH 1/5] tools lib api: Add debug output support Jiri Olsa <jolsa@kernel.org> - 2016-02-14 17:10 +0100
[tip:perf/core] tools lib api: Add debug output support tip-bot for Jiri Olsa <tipbot@zytor.com> - 2016-02-17 13:10 +0100
[PATCH 2/5] tools lib api fs: Move filename__read_str into api/fs/fs.c Jiri Olsa <jolsa@kernel.org> - 2016-02-14 17:10 +0100
[tip:perf/core] tools lib api fs: Adopt filename__read_str from perf tip-bot for Jiri Olsa <tipbot@zytor.com> - 2016-02-17 13:10 +0100
Re: [PATCH 0/5] perf tools: Store CPU cache details under perf data Ingo Molnar <mingo@kernel.org> - 2016-02-16 09:20 +0100
Re: [PATCH 0/5] perf tools: Store CPU cache details under perf data Jiri Olsa <jolsa@redhat.com> - 2016-02-16 12:30 +0100
csiph-web