Files
fastfetch/src/detection/gpu/gpu_android.c
T

56 lines
1.6 KiB
C
Raw Normal View History

#include "gpu.h"
2026-01-06 09:48:38 +08:00
#include "common/io.h"
2026-05-28 15:58:08 +08:00
#include "common/strutil.h"
#include <fcntl.h>
2026-03-29 09:28:49 +08:00
static double parseTZDir(int dfd, FFstrbuf* buffer) {
if (!ffReadFileBufferRelative(dfd, "type", buffer) || !ffStrbufStartsWithS(buffer, "gpu")) {
return FF_GPU_TEMP_UNSET;
2026-03-29 09:28:49 +08:00
}
2026-03-29 09:28:49 +08:00
if (!ffReadFileBufferRelative(dfd, "temp", buffer)) {
return FF_GPU_TEMP_UNSET;
2026-03-29 09:28:49 +08:00
}
2026-03-29 09:28:49 +08:00
double value = ffStrbufToDouble(buffer, FF_GPU_TEMP_UNSET); // millidegree Celsius
if (value == FF_GPU_TEMP_UNSET) {
return FF_GPU_TEMP_UNSET;
2026-03-29 09:28:49 +08:00
}
return value / 1000.;
}
2026-03-29 09:28:49 +08:00
double ffGPUDetectTempFromTZ(void) {
FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/sys/class/thermal/");
2026-03-29 09:28:49 +08:00
if (dirp) {
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
int dfd = dirfd(dirp);
struct dirent* entry;
2026-03-29 09:28:49 +08:00
while ((entry = readdir(dirp)) != NULL) {
if (entry->d_name[0] == '.') {
continue;
2026-03-29 09:28:49 +08:00
}
if (!ffStrStartsWith(entry->d_name, "thermal_zone")) {
continue;
2026-03-29 09:28:49 +08:00
}
FF_AUTO_CLOSE_FD int subfd = openat(dfd, entry->d_name, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
2026-03-29 09:28:49 +08:00
if (subfd < 0) {
continue;
2026-03-29 09:28:49 +08:00
}
double result = parseTZDir(subfd, &buffer);
2026-03-29 09:28:49 +08:00
if (result != FF_GPU_TEMP_UNSET) {
return result;
2026-03-29 09:28:49 +08:00
}
}
}
return FF_GPU_TEMP_UNSET;
}
2026-03-29 09:28:49 +08:00
const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus) {
FF_UNUSED(options, gpus);
return "No permission. Fallbacks to Vulkan, OpenCL or OpenGL instead";
}