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 <gautham.shenoy@amd.com>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Wyes Karny <wyes.karny@amd.com>
Tested-by: Perry Yuan <Perry.Yuan@amd.com>
Acked-by: Huang Rui <ray.huang@amd.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
This commit is contained in:
Wyes Karny 2023-06-19 19:05:00 +00:00 committed by Shuah Khan
parent a1cf97c2d4
commit 1ce5ab7c1d
2 changed files with 8 additions and 0 deletions

View file

@ -14,6 +14,13 @@
#include "cpupower.h"
#include "cpupower_intern.h"
int is_valid_path(const char *path)
{
if (access(path, F_OK) == -1)
return 0;
return 1;
}
unsigned int cpupower_read_sysfs(const char *path, char *buf, size_t buflen)
{
ssize_t numread;

View file

@ -7,5 +7,6 @@
#define SYSFS_PATH_MAX 255
int is_valid_path(const char *path);
unsigned int cpupower_read_sysfs(const char *path, char *buf, size_t buflen);
unsigned int cpupower_write_sysfs(const char *path, char *buf, size_t buflen);