mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 16:00:39 +01:00
[v0.96] Consider the case where present file does not contain a hyphen
This commit is contained in:
@@ -18,9 +18,9 @@
|
||||
int get_ncores_from_cpuinfo() {
|
||||
// Examples:
|
||||
// 0-271
|
||||
// 0-5
|
||||
// 0-7
|
||||
/*
|
||||
// 0
|
||||
|
||||
int filelen;
|
||||
char* buf;
|
||||
if((buf = read_file(_PATH_CPUS_PRESENT, &filelen)) == NULL) {
|
||||
@@ -28,8 +28,16 @@ int get_ncores_from_cpuinfo() {
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
int ncores = 0;
|
||||
char* tmp1 = strstr(buf, "-") + 1;
|
||||
int ncores;
|
||||
char* tmp1;
|
||||
if((tmp1 = strstr(buf, "-")) == NULL) {
|
||||
// file contains no - character, we assume that it contains 0,
|
||||
// which means that the CPU contains only one core
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
tmp1++;
|
||||
}
|
||||
char* tmp2 = strstr(buf, "\n");
|
||||
char ncores_str[filelen];
|
||||
memset(ncores_str, 0, sizeof(char) * filelen);
|
||||
@@ -43,9 +51,9 @@ int get_ncores_from_cpuinfo() {
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
free(buf);*/
|
||||
free(buf);
|
||||
|
||||
return 1;
|
||||
return ncores;
|
||||
}
|
||||
|
||||
long parse_cpuinfo_field(char* buf, char* field_str, int field_base) {
|
||||
|
||||
Reference in New Issue
Block a user