Files
fastfetch/src/detection/loadavg/loadavg_linux.c
T
2026-07-10 18:10:09 +08:00

34 lines
830 B
C

#include "detection/loadavg/loadavg.h"
#include "common/io.h"
#include <sys/sysinfo.h>
const char* ffDetectLoadavg(double result[3]) {
#ifndef __ANDROID__ // cat: /proc/loadavg: Permission denied
// Don't use syscall for container compatibility. #620
char buf[64];
ssize_t nRead = ffReadFileData("/proc/loadavg", sizeof(buf) - 1, buf);
if (nRead > 0) {
buf[nRead] = '\0';
if (sscanf(buf, "%lf%lf%lf", &result[0], &result[1], &result[2]) == 3) {
return nullptr;
}
}
#endif
#ifndef __GNU__
// getloadavg requires higher ANDROID_API version
struct sysinfo si;
if (sysinfo(&si) < 0) {
return "sysinfo() failed";
}
for (int i = 0; i < 3; i++) {
result[i] = (double) si.loads[i] / (1 << SI_LOAD_SHIFT);
}
#endif
return nullptr;
}