aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/api
diff options
context:
space:
mode:
Diffstat (limited to 'tools/lib/api')
-rw-r--r--tools/lib/api/fs/fs.c29
-rw-r--r--tools/lib/api/fs/fs.h1
2 files changed, 30 insertions, 0 deletions
diff --git a/tools/lib/api/fs/fs.c b/tools/lib/api/fs/fs.c
index 4b6bfc43cccf..809c7721cd24 100644
--- a/tools/lib/api/fs/fs.c
+++ b/tools/lib/api/fs/fs.c
@@ -439,6 +439,35 @@ int sysfs__read_str(const char *entry, char **buf, size_t *sizep)
439 return filename__read_str(path, buf, sizep); 439 return filename__read_str(path, buf, sizep);
440} 440}
441 441
442int sysfs__read_bool(const char *entry, bool *value)
443{
444 char *buf;
445 size_t size;
446 int ret;
447
448 ret = sysfs__read_str(entry, &buf, &size);
449 if (ret < 0)
450 return ret;
451
452 switch (buf[0]) {
453 case '1':
454 case 'y':
455 case 'Y':
456 *value = true;
457 break;
458 case '0':
459 case 'n':
460 case 'N':
461 *value = false;
462 break;
463 default:
464 ret = -1;
465 }
466
467 free(buf);
468
469 return ret;
470}
442int sysctl__read_int(const char *sysctl, int *value) 471int sysctl__read_int(const char *sysctl, int *value)
443{ 472{
444 char path[PATH_MAX]; 473 char path[PATH_MAX];
diff --git a/tools/lib/api/fs/fs.h b/tools/lib/api/fs/fs.h
index 6b332dc74498..956c21127d1e 100644
--- a/tools/lib/api/fs/fs.h
+++ b/tools/lib/api/fs/fs.h
@@ -37,4 +37,5 @@ int sysctl__read_int(const char *sysctl, int *value);
37int sysfs__read_int(const char *entry, int *value); 37int sysfs__read_int(const char *entry, int *value);
38int sysfs__read_ull(const char *entry, unsigned long long *value); 38int sysfs__read_ull(const char *entry, unsigned long long *value);
39int sysfs__read_str(const char *entry, char **buf, size_t *sizep); 39int sysfs__read_str(const char *entry, char **buf, size_t *sizep);
40int sysfs__read_bool(const char *entry, bool *value);
40#endif /* __API_FS__ */ 41#endif /* __API_FS__ */