aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConnor Imes <connor.k.imes@gmail.com>2021-04-10 19:11:25 -0400
committerConnor Imes <connor.k.imes@gmail.com>2021-04-10 19:11:25 -0400
commit868246c1bd9cbea6b30defdb9004392e6498f7eb (patch)
treec96e052c1e5a7b01d6fdd5aecc414595ed0bc69f
parentde87ba353ca3e0f6ec45d557c36a111731015619 (diff)
powercap-common: mv is_valid_control_type from sysfs to common
-rw-r--r--src/powercap-common.c4
-rw-r--r--src/powercap-common.h3
-rw-r--r--src/powercap-sysfs.c5
3 files changed, 7 insertions, 5 deletions
diff --git a/src/powercap-common.c b/src/powercap-common.c
index 05cd425..e6b145f 100644
--- a/src/powercap-common.c
+++ b/src/powercap-common.c
@@ -113,6 +113,10 @@ int write_u64(int fd, uint64_t val) {
return 0;
}
+int is_valid_control_type(const char* control_type) {
+ return control_type && strlen(control_type) && strcspn(control_type, "./") == strlen(control_type);
+}
+
int snprintf_base_path(char* buf, size_t size, const char* control_type, const uint32_t* zones, uint32_t depth) {
int w;
int tot;
diff --git a/src/powercap-common.h b/src/powercap-common.h
index b1d8278..6e31252 100644
--- a/src/powercap-common.h
+++ b/src/powercap-common.h
@@ -64,6 +64,9 @@ int read_u64(int fd, uint64_t* val);
/* Return 0 on success, negative error code on failure */
int write_u64(int fd, uint64_t val);
+/* Simple names only, trying to look outside the powercap directory is not allowed */
+int is_valid_control_type(const char* control_type);
+
/*
* Return is like snprintf, except if the output was truncated due to the size limit, the return value is still > size,
* but not necessarily the number of characters (excluding the terminating null byte) which would have been written to
diff --git a/src/powercap-sysfs.c b/src/powercap-sysfs.c
index 81f1e3c..5795d20 100644
--- a/src/powercap-sysfs.c
+++ b/src/powercap-sysfs.c
@@ -21,11 +21,6 @@
#include "powercap-common.h"
#include "powercap-sysfs.h"
-static int is_valid_control_type(const char* control_type) {
- /* simple names only, trying to look outside the powercap directory is not allowed */
- return control_type && strlen(control_type) && strcspn(control_type, "./") == strlen(control_type);
-}
-
static int control_type_read_u64(const char* control_type, uint64_t* val, powercap_control_type_file type) {
char path[PATH_MAX];
int ret;