Loadavg (Android): fix compiling

This commit is contained in:
李通洲
2024-05-08 21:54:13 +08:00
parent df3fa6f8a8
commit 852c6abf2e
3 changed files with 35 additions and 4 deletions
+2 -2
View File
@@ -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
+8
View File
@@ -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;
}
+25 -2
View File
@@ -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;
}