forked from Master-0f-None/OhGodATool
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ohgodatool-utils.c
48 lines (37 loc) · 1.04 KB
/
ohgodatool-utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (c) 2017 OhGodACompany - OhGodAGirl & OhGodAPet
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
// Must be freed by caller unless NULL
void GetGPUHWMonPath(char **HWMonPath, uint32_t GPUIdx)
{
DIR *hwmon;
char TempPath[256];
struct dirent *inner_hwmon;
// Set it to NULL (indicating failure) until we need to use it
*HWMonPath = NULL;
sprintf(TempPath, "/sys/class/drm/card%d/device/hwmon", GPUIdx);
hwmon = opendir(TempPath);
if(!hwmon)
{
printf("Unable to open hwmon dir for GPU %d.\n", GPUIdx);
return;
}
for(;;)
{
inner_hwmon = readdir(hwmon);
if(!inner_hwmon) break;
if(inner_hwmon->d_type != DT_DIR) continue;
if(!memcmp(inner_hwmon->d_name, "hwmon", 5)) break;
}
if(!inner_hwmon)
{
printf("Unable to open hwmon dir for GPU %d.\n", GPUIdx);
return;
}
*HWMonPath = (char *)malloc(sizeof(char) * (256 + strlen(inner_hwmon->d_name)));
sprintf(*HWMonPath, "/sys/class/drm/card%d/device/hwmon/%s", GPUIdx, inner_hwmon->d_name);
return;
}