X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/609ef3aa1f6c0a47822d425dc6bb0744042ca038..c93971748cb4771aec25aee6e8ff5b7bbb1aacf3:/components/battery.c?ds=sidebyside diff --git a/components/battery.c b/components/battery.c index 82e0baf..79d16c2 100644 --- a/components/battery.c +++ b/components/battery.c @@ -6,6 +6,7 @@ #if defined(__linux__) #include + #include #include static const char * @@ -76,7 +77,7 @@ const char * battery_remaining(const char *bat) { - int charge_now, current_now, m, h; + uintmax_t charge_now, current_now, m, h; double timeleft; char path[PATH_MAX], state[12]; @@ -92,7 +93,7 @@ if (!pick(bat, "/sys/class/power_supply/%s/charge_now", "/sys/class/power_supply/%s/energy_now", path, sizeof(path)) || - pscanf(path, "%d", &charge_now) < 0) { + pscanf(path, "%ju", &charge_now) < 0) { return NULL; } @@ -100,7 +101,7 @@ if (!pick(bat, "/sys/class/power_supply/%s/current_now", "/sys/class/power_supply/%s/power_now", path, sizeof(path)) || - pscanf(path, "%d", ¤t_now) < 0) { + pscanf(path, "%ju", ¤t_now) < 0) { return NULL; } @@ -112,7 +113,7 @@ h = timeleft; m = (timeleft - (double)h) * 60; - return bprintf("%dh %dm", h, m); + return bprintf("%juh %jum", h, m); } return "";