Skip to content

Commit

Permalink
tools lib api fs: Introduce sysfs__read_bool
Browse files Browse the repository at this point in the history
Will be used in a upcoming patch warning about PERF_RECORD_AUX data
gaps, reading the "module/kvm_intel/parameters/vmm_exclusive" sysfs
entry.

Signed-off-by: Alexander Shishkin <[email protected]>
Tested-by: Arnaldo Carvalho de Melo <[email protected]>
Cc: Adrian Hunter <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Cc: Vince Weaver <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
[ split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
virtuoso authored and acmel committed Mar 17, 2017
1 parent f371594 commit b9835a9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tools/lib/api/fs/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,35 @@ int sysfs__read_str(const char *entry, char **buf, size_t *sizep)
return filename__read_str(path, buf, sizep);
}

int sysfs__read_bool(const char *entry, bool *value)
{
char *buf;
size_t size;
int ret;

ret = sysfs__read_str(entry, &buf, &size);
if (ret < 0)
return ret;

switch (buf[0]) {
case '1':
case 'y':
case 'Y':
*value = true;
break;
case '0':
case 'n':
case 'N':
*value = false;
break;
default:
ret = -1;
}

free(buf);

return ret;
}
int sysctl__read_int(const char *sysctl, int *value)
{
char path[PATH_MAX];
Expand Down
1 change: 1 addition & 0 deletions tools/lib/api/fs/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ 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);
int sysfs__read_bool(const char *entry, bool *value);
#endif /* __API_FS__ */

0 comments on commit b9835a9

Please sign in to comment.