summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorplanet36 <planet36@users.noreply.github.com>2021-04-06 12:48:18 -0400
committerRafael Marçalo <raroma09@gmail.com>2023-01-03 15:02:26 +0000
commit9a18d072ba2ad2e2b95659fe9dd367abc0fe463a (patch)
treef957ba7a91e9a87605c1c7d416073d44853a1840
parent0bd65f246865c86849dfc33597c8efaf1297a474 (diff)
battery: Consistent naming for capacity percentage
https://www.kernel.org/doc/html/latest/power/power_supply_class.html Co-authored-by: drkhsh <me@drkhsh.at> Signed-off-by: drkhsh <me@drkhsh.at>
-rw-r--r--components/battery.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/components/battery.c b/components/battery.c
index 9fa1014..1c753f9 100644
--- a/components/battery.c
+++ b/components/battery.c
@@ -6,6 +6,9 @@
#include "../util.h"
#if defined(__linux__)
+/*
+ * https://www.kernel.org/doc/html/latest/power/power_supply_class.html
+ */
#include <limits.h>
#include <stdint.h>
#include <unistd.h>
@@ -35,15 +38,15 @@
const char *
battery_perc(const char *bat)
{
- int perc;
+ int cap_perc;
char path[PATH_MAX];
if (esnprintf(path, sizeof(path), POWER_SUPPLY_CAPACITY, bat) < 0)
return NULL;
- if (pscanf(path, "%d", &perc) != 1)
+ if (pscanf(path, "%d", &cap_perc) != 1)
return NULL;
- return bprintf("%d", perc);
+ return bprintf("%d", cap_perc);
}
const char *
@@ -197,14 +200,14 @@
const char *
battery_perc(const char *unused)
{
- int cap;
+ int cap_perc;
size_t len;
- len = sizeof(cap);
- if (sysctlbyname(BATTERY_LIFE, &cap, &len, NULL, 0) < 0 || !len)
+ len = sizeof(cap_perc);
+ if (sysctlbyname(BATTERY_LIFE, &cap_perc, &len, NULL, 0) < 0 || !len)
return NULL;
- return bprintf("%d", cap);
+ return bprintf("%d", cap_perc);
}
const char *