Xinqi Bao's Git

ram: Consistency with line breaks
[slstatus.git] / components / battery.c
index 82e0baf..1178f20 100644 (file)
@@ -6,6 +6,7 @@
 
 #if defined(__linux__)
        #include <limits.h>
+       #include <stdint.h>
        #include <unistd.h>
 
        static const char *
@@ -32,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) {
@@ -57,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) {
        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];
 
                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) {
@@ -90,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, "%d", &charge_now) < 0) {
+                         "/sys/class/power_supply/%s/energy_now", path,
+                         sizeof(path)) ||
+                   pscanf(path, "%ju", &charge_now) < 0) {
                        return NULL;
                }
 
                        if (!pick(bat, "/sys/class/power_supply/%s/current_now",
                                  "/sys/class/power_supply/%s/power_now", path,
                                  sizeof(path)) ||
-                           pscanf(path, "%d", &current_now) < 0) {
+                           pscanf(path, "%ju", &current_now) < 0) {
                                return NULL;
                        }
 
                        h = timeleft;
                        m = (timeleft - (double)h) * 60;
 
-                       return bprintf("%dh %dm", h, m);
+                       return bprintf("%juh %jum", h, m);
                }
 
                return "";