Skip to content

Commit 1ce5ab7

Browse files
wkarnyshuahkh
authored andcommitted
cpupower: Add is_valid_path API
Add is_valid_path API to check whether the sysfs file is present or not. Suggested-by: Gautham R. Shenoy <[email protected]> Reviewed-by: Mario Limonciello <[email protected]> Signed-off-by: Wyes Karny <[email protected]> Tested-by: Perry Yuan <[email protected]> Acked-by: Huang Rui <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent a1cf97c commit 1ce5ab7

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

tools/power/cpupower/lib/cpupower.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
#include "cpupower.h"
1515
#include "cpupower_intern.h"
1616

17+
int is_valid_path(const char *path)
18+
{
19+
if (access(path, F_OK) == -1)
20+
return 0;
21+
return 1;
22+
}
23+
1724
unsigned int cpupower_read_sysfs(const char *path, char *buf, size_t buflen)
1825
{
1926
ssize_t numread;

tools/power/cpupower/lib/cpupower_intern.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77

88
#define SYSFS_PATH_MAX 255
99

10+
int is_valid_path(const char *path);
1011
unsigned int cpupower_read_sysfs(const char *path, char *buf, size_t buflen);
1112
unsigned int cpupower_write_sysfs(const char *path, char *buf, size_t buflen);

0 commit comments

Comments
 (0)