X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/43a12832a343747b7317987b552a87eb8ed5b42d..dd7f1896aa9883f33b4d28cd192e8088db0cab5a:/components/battery.c diff --git a/components/battery.c b/components/battery.c index ae31dd6..1178f20 100644 --- a/components/battery.c +++ b/components/battery.c @@ -5,8 +5,8 @@ #include "../util.h" #if defined(__linux__) - #include #include + #include #include static const char * @@ -33,8 +33,7 @@ char path[PATH_MAX]; if (esnprintf(path, sizeof(path), - "/sys/class/power_supply/%s/capacity", - bat) < 0) { + "/sys/class/power_supply/%s/capacity", bat) < 0) { return NULL; } if (pscanf(path, "%d", &perc) != 1) { @@ -58,8 +57,7 @@ char path[PATH_MAX], state[12]; if (esnprintf(path, sizeof(path), - "/sys/class/power_supply/%s/status", - bat) < 0) { + "/sys/class/power_supply/%s/status", bat) < 0) { return NULL; } if (pscanf(path, "%12s", state) != 1) { @@ -82,8 +80,7 @@ char path[PATH_MAX], state[12]; if (esnprintf(path, sizeof(path), - "/sys/class/power_supply/%s/status", - bat) < 0) { + "/sys/class/power_supply/%s/status", bat) < 0) { return NULL; } if (pscanf(path, "%12s", state) != 1) { @@ -91,9 +88,9 @@ } if (!pick(bat, "/sys/class/power_supply/%s/charge_now", - "/sys/class/power_supply/%s/energy_now", - path, sizeof(path)) || - pscanf(path, "%" PRIuMAX, &charge_now) < 0) { + "/sys/class/power_supply/%s/energy_now", path, + sizeof(path)) || + pscanf(path, "%ju", &charge_now) < 0) { return NULL; } @@ -101,7 +98,7 @@ if (!pick(bat, "/sys/class/power_supply/%s/current_now", "/sys/class/power_supply/%s/power_now", path, sizeof(path)) || - pscanf(path, "%" PRIuMAX, ¤t_now) < 0) { + pscanf(path, "%ju", ¤t_now) < 0) { return NULL; } @@ -113,7 +110,7 @@ h = timeleft; m = (timeleft - (double)h) * 60; - return bprintf("%" PRIuMAX "h %" PRIuMAX "m", h, m); + return bprintf("%juh %jum", h, m); } return "";