summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author諏訪子 <suwako@076.moe>2024-06-21 19:12:37 +0900
committer諏訪子 <suwako@076.moe>2024-06-21 19:12:37 +0900
commit5e31ce485184c202175ca95d03c17389694bd6aa (patch)
tree0e45059a119bd2f571b3dcaf3e68fab750a77037 /src
parent8e09e19b21140193cf27de835cdad87710fd2c85 (diff)
Linux: CPU情報の修正
Diffstat (limited to 'src')
-rw-r--r--src/cpu.c31
1 files changed, 6 insertions, 25 deletions
diff --git a/src/cpu.c b/src/cpu.c
index 780cba1..f479517 100644
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -20,36 +20,17 @@ const char *display_cpu() {
"sed 's/ CPU//' | sed 's/^ *//' && "
"echo \" (\" && psrinfo -p && echo \" core)\"");
#elif defined(__linux__)
- char buf[20];
- long int val;
- double fmt;
- FILE *fp = fopen("/sys/devices/system/cpu/cpu0/cpufreq/bios_limit", "r");
- if (fp == NULL) {
- fp = fopen("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq", "r");
- }
-
- if (fp == NULL) {
- perror("失敗");
- return NULL;
- }
-
- if (fgets(buf, sizeof(buf), fp) != NULL) {
- val = strtol(buf, NULL, 10);
- fmt = val / 1000000.0;
- printf("%.2f", fmt);
- } else {
- perror("失敗");
- fclose(fp);
- return NULL;
- }
-
- fclose(fp);
-
return run_command_s("cat /proc/cpuinfo | awk -F '\\\\s*: | @' "
"'/model name|Hardware|Processor|^cpu model|chip type|^cpu type/ { "
"cpu=$2; if ($1 == \"Hardware\") exit } END { print cpu }' | "
"sed 's/(R)//' | sed 's/(TM)//' | sed 's/CPU //' | sed 's/ Processor//' | "
"sed 's/ [0-9]-Core//' && echo \" @ \" && "
+ "if [ \"$(LC_ALL=C cat /sys/devices/system/cpu/cpu0/cpufreq/bios_limit 2>&1)\""
+ " != \"cat: /sys/devices/system/cpu/cpu0/cpufreq/bios_limit: "
+ "No such file or directory\" ]; then "
+ "cat /sys/devices/system/cpu/cpu0/cpufreq/bios_limit; else "
+ "cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq | "
+ "awk '{printf \"%.2f\", $1/1000000}'; fi && "
"echo \"GHz (\" && nproc && echo \" core)\"");
#endif
return NULL;