mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 16:00:39 +01:00
[v0.98][PPC] Refactor PowerPC udev functions
This commit is contained in:
@@ -3,14 +3,14 @@
|
||||
#define _PATH_TOPO_CORE_ID "topology/core_id"
|
||||
#define _PATH_TOPO_PACKAGE_ID "topology/physical_package_id"
|
||||
|
||||
bool fill_core_ids_from_sys(int *core_ids, int total_cores) {
|
||||
bool fill_array_from_sys(int *core_ids, int total_cores, char* SYS_PATH) {
|
||||
int filelen;
|
||||
char* buf;
|
||||
char* end;
|
||||
char path[128];
|
||||
|
||||
for(int i=0; i < total_cores; i++) {
|
||||
sprintf(path, "%s%s/cpu%d/%s", _PATH_SYS_SYSTEM, _PATH_SYS_CPU, i, _PATH_TOPO_CORE_ID);
|
||||
sprintf(path, "%s%s/cpu%d/%s", _PATH_SYS_SYSTEM, _PATH_SYS_CPU, i, SYS_PATH);
|
||||
if((buf = read_file(path, &filelen)) == NULL) {
|
||||
perror("open");
|
||||
return false;
|
||||
@@ -28,22 +28,10 @@ bool fill_core_ids_from_sys(int *core_ids, int total_cores) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool fill_package_ids_from_sys(int* package_ids, int total_cores) {
|
||||
int filelen;
|
||||
char* buf;
|
||||
char* end;
|
||||
char path[128];
|
||||
|
||||
for(int i=0; i < total_cores; i++) {
|
||||
sprintf(path, "%s%s/cpu%d/%s", _PATH_SYS_SYSTEM, _PATH_SYS_CPU, i, _PATH_TOPO_PACKAGE_ID);
|
||||
buf = read_file(path, &filelen);
|
||||
|
||||
errno = 0;
|
||||
package_ids[i] = strtol(buf, &end, 10);
|
||||
if(errno != 0) {
|
||||
perror("strtol");
|
||||
return -1;
|
||||
}
|
||||
free(buf);
|
||||
}
|
||||
bool fill_core_ids_from_sys(int *core_ids, int total_cores) {
|
||||
return fill_array_from_sys(core_ids, total_cores, _PATH_TOPO_CORE_ID);
|
||||
}
|
||||
|
||||
bool fill_package_ids_from_sys(int* package_ids, int total_cores) {
|
||||
return fill_array_from_sys(package_ids, total_cores, _PATH_TOPO_PACKAGE_ID);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user