aboutsummaryrefslogtreecommitdiff
path: root/getgov.c
diff options
context:
space:
mode:
authorDavid Phillips <dbphillipsnz@gmail.com>2015-09-01 21:19:01 +1200
committerDavid Phillips <dbphillipsnz@gmail.com>2015-09-01 21:39:20 +1200
commit32bff14871bf8f534fcdcdba1d8409430d6c464b (patch)
tree6de6cd2cda5cc91d76ae2fac8764270a01cb260c /getgov.c
parent841445fb7a482b9c1ed9eca896d308afab4316d8 (diff)
downloadparamano-32bff14871bf8f534fcdcdba1d8409430d6c464b.tar.xz
Conforming to style, switching paramano-set to getopt (finally)
Diffstat (limited to 'getgov.c')
-rw-r--r--getgov.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/getgov.c b/getgov.c
index 7ff8562..f75e6c9 100644
--- a/getgov.c
+++ b/getgov.c
@@ -27,20 +27,20 @@ static int total_governors;
**********************************************************************/
void gg_init()
{
- gchar gov_string[500];
+ char gov_string[500];
unsigned int i = 0;
total_governors = 0;
+
for (i = 0; i < gc_number(); i++)
{
memset(gov_string, '\0', sizeof(gov_string) );
gg_available(i, gov_string, sizeof(gov_string) );
- // go through every governor in gov_string
- gchar* curr = (char*)&gov_string;
- gchar* end_of_curr = g_strstr_len(curr, strlen(curr), " ");
+ char* curr = gov_string;
+ char* end_of_curr = g_strstr_len(curr, strlen(curr), " ");
while (end_of_curr)
{
- memset(governors[i][total_governors], '\0', 13);
+ memset(governors[i][total_governors], '\0', 13); /* FIXME magic */
memmove(governors[i][total_governors], curr, end_of_curr - curr);
curr = end_of_curr+1;
@@ -56,20 +56,17 @@ void gg_init()
**********************************************************************/
bool gg_current(int core, char* out, int size)
{
- FILE* fd;
+ FILE* fd = NULL;
char path[1024];
+
snprintf(path, sizeof(path), "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor", core);
if (!(fd = fopen(path, "r")))
return false;
fgets(out, size, fd);
-
- // Get first line
- gchar* newline = g_strrstr(out, "\n");
- *newline = '\0';
-
fclose(fd);
+ chomp(out);
return true;
}
@@ -79,8 +76,9 @@ bool gg_current(int core, char* out, int size)
**********************************************************************/
bool gg_available(int core, char* out, int size)
{
+ FILE *fd = NULL;
char path[1024];
- FILE *fd;
+
snprintf(path, sizeof(path), "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_available_governors", core);
if (!(fd = fopen(path, "r")))