mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Loadavg (Android): fix compiling
This commit is contained in:
+2
-2
@@ -541,7 +541,7 @@ elseif(BSD)
|
||||
src/detection/lm/lm_linux.c
|
||||
src/detection/icons/icons_linux.c
|
||||
src/detection/libc/libc_bsd.c
|
||||
src/detection/loadavg/loadavg_linux.c
|
||||
src/detection/loadavg/loadavg_bsd.c
|
||||
src/detection/locale/locale_linux.c
|
||||
src/detection/localip/localip_linux.c
|
||||
src/detection/gamepad/gamepad_bsd.c
|
||||
@@ -598,7 +598,7 @@ elseif(APPLE)
|
||||
src/detection/host/host_apple.c
|
||||
src/detection/icons/icons_nosupport.c
|
||||
src/detection/lm/lm_nosupport.c
|
||||
src/detection/loadavg/loadavg_linux.c
|
||||
src/detection/loadavg/loadavg_bsd.c
|
||||
src/detection/libc/libc_apple.c
|
||||
src/detection/locale/locale_linux.c
|
||||
src/detection/localip/localip_linux.c
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
#include "detection/loadavg/loadavg.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
const char* ffDetectLoadavg(double result[3])
|
||||
{
|
||||
return getloadavg(result, 3) < 0 ? "getloadavg() failed" : NULL;
|
||||
}
|
||||
@@ -1,8 +1,31 @@
|
||||
#include "detection/loadavg/loadavg.h"
|
||||
#include "common/io/io.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sys/sysinfo.h>
|
||||
|
||||
const char* ffDetectLoadavg(double result[3])
|
||||
{
|
||||
return getloadavg(result, 3) < 0 ? "getloadavg() failed" : NULL;
|
||||
#ifndef __ANDROID__ // cat: /proc/loadavg: Permission denied
|
||||
|
||||
// Don't use syscall for container compatibility. #620
|
||||
char buf[64];
|
||||
ssize_t nRead = ffReadFileData("/proc/uptime", sizeof(buf) - 1, buf);
|
||||
if (nRead > 0)
|
||||
{
|
||||
buf[nRead] = '\0';
|
||||
|
||||
if (sscanf(buf, "%lf %lf %lf", &result[0], &result[1], &result[2]) == 3)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// 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);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user