Skip to content

Commit 51c0396

Browse files
olsajiriacmel
authored andcommitted
tools lib api fs: Add sysfs__read_str function
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); Signed-off-by: Jiri Olsa <[email protected]> Cc: David Ahern <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 607bfbd commit 51c0396

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

tools/lib/api/fs/fs.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,19 @@ int sysfs__read_int(const char *entry, int *value)
377377
return filename__read_int(path, value);
378378
}
379379

380+
int sysfs__read_str(const char *entry, char **buf, size_t *sizep)
381+
{
382+
char path[PATH_MAX];
383+
const char *sysfs = sysfs__mountpoint();
384+
385+
if (!sysfs)
386+
return -1;
387+
388+
snprintf(path, sizeof(path), "%s/%s", sysfs, entry);
389+
390+
return filename__read_str(path, buf, sizep);
391+
}
392+
380393
int sysctl__read_int(const char *sysctl, int *value)
381394
{
382395
char path[PATH_MAX];

tools/lib/api/fs/fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ int filename__read_str(const char *filename, char **buf, size_t *sizep);
3232
int sysctl__read_int(const char *sysctl, int *value);
3333
int sysfs__read_int(const char *entry, int *value);
3434
int sysfs__read_ull(const char *entry, unsigned long long *value);
35+
int sysfs__read_str(const char *entry, char **buf, size_t *sizep);
3536
#endif /* __API_FS__ */

0 commit comments

Comments
 (0)