aboutsummaryrefslogtreecommitdiffstats
path: root/cputemp.c
diff options
context:
space:
mode:
authorPA4WDH2024-07-28 16:36:07 +0200
committerPA4WDH2024-07-28 16:36:07 +0200
commit0406047a1c47ea9092b6527fd8f0150d1ed3b1db (patch)
treeb2a873a7917eea0a05d1400823263969b0050546 /cputemp.c
parentMove matching/validating code to cputemp_match_and_validate (diff)
downloadcputemp2maxfreq-0406047a1c47ea9092b6527fd8f0150d1ed3b1db.tar.gz
cputemp2maxfreq-0406047a1c47ea9092b6527fd8f0150d1ed3b1db.tar.bz2
cputemp2maxfreq-0406047a1c47ea9092b6527fd8f0150d1ed3b1db.zip
Move file name matching to separate function
Diffstat (limited to 'cputemp.c')
-rw-r--r--cputemp.c58
1 files changed, 35 insertions, 23 deletions
diff --git a/cputemp.c b/cputemp.c
index 4276e54..e30cc31 100644
--- a/cputemp.c
+++ b/cputemp.c
@@ -46,12 +46,39 @@ void cputemp_match_and_validate(char *name_file,char *input_file,char *sensor_na
}
}
+// Validate if we found a file named temp<number>_label
+int cputemp_is_label(char *name)
+{
+ int count;
+ int offset;
+
+// Start with "temp"
+ if (strncmp(name,"temp",4)!=0) return 0;
+
+// Must contain an underscore
+ offset=0;
+ for(count=5;count<7;count++)
+ {
+ if (name[count]=='_')
+ {
+ offset=count+1;
+ break;
+ }
+ }
+ if (offset==0) return 0;
+
+// Ends with "label"
+ if (strncmp(name+offset,"label",5)!=0) return 0;
+ if (name[offset+5]==0) return 1;
+
+ return 0;
+}
+
// Read a single hwmon directory and search for the requested sensor name
void cputemp_read_hwmon(char *hwmon,char *sensor_name,struct s_sensor *sensor)
{
DIR *hwmon_dir;
struct dirent *hwmon_dirent;
- int count;
char name_file[255];
char input_file[255];
int offset;
@@ -70,29 +97,14 @@ void cputemp_read_hwmon(char *hwmon,char *sensor_name,struct s_sensor *sensor)
{
DEBUG3_CPUTEMP("%s\n",hwmon_dirent->d_name);
-// We are searching for files named "temp<number>_label"
- if (strncmp(hwmon_dirent->d_name,"temp",4)==0)
+ if (cputemp_is_label(hwmon_dirent->d_name))
{
- DEBUG3_CPUTEMP("Found temp entry: %s\n",hwmon_dirent->d_name);
- offset=0;
- for(count=5;count<7;count++)
- {
- if (hwmon_dirent->d_name[count]=='_')
- {
- DEBUG3_CPUTEMP("Underscore at %d\n",count);
- offset=count+1;
- break;
- }
- }
- if (strncmp(hwmon_dirent->d_name+offset,"label",5)==0)
- {
- DEBUG2_CPUTEMP("Found label %s\n",hwmon_dirent->d_name);
- sprintf(name_file,"%s/%s",hwmon,hwmon_dirent->d_name);
- sprintf(input_file,"%s/%s",hwmon,hwmon_dirent->d_name);
- offset=strlen(input_file)-5;
- strncpy(input_file+offset,"input",5);
- cputemp_match_and_validate(name_file,input_file,sensor_name,sensor);
- }
+ DEBUG2_CPUTEMP("Found label %s\n",hwmon_dirent->d_name);
+ sprintf(name_file,"%s/%s",hwmon,hwmon_dirent->d_name);
+ sprintf(input_file,"%s/%s",hwmon,hwmon_dirent->d_name);
+ offset=strlen(input_file)-5;
+ strncpy(input_file+offset,"input",5);
+ cputemp_match_and_validate(name_file,input_file,sensor_name,sensor);
}
hwmon_dirent=readdir(hwmon_dir);
}