[hackers] [slstatus] battery: 64 bit ints on Linux || Aaron Marcher

From: <git_AT_suckless.org>
Date: Sat, 7 Jul 2018 10:32:21 +0200 (CEST)

commit d76b1a21fc014395cf9f7bd4e14180a3a0945e9c
Author: Aaron Marcher <me_AT_drkhsh.at>
AuthorDate: Sat Jul 7 10:31:57 2018 +0200
Commit: Aaron Marcher <me_AT_drkhsh.at>
CommitDate: Sat Jul 7 10:31:57 2018 +0200

    battery: 64 bit ints on Linux

diff --git a/components/battery.c b/components/battery.c
index 82e0baf..31c7d48 100644
--- a/components/battery.c
+++ b/components/battery.c
_AT_@ -5,6 +5,7 @@
 #include "../util.h"
 
 #if defined(__linux__)
+ #include <inttypes.h>
         #include <limits.h>
         #include <unistd.h>
 
_AT_@ -76,7 +77,7 @@
         const char *
         battery_remaining(const char *bat)
         {
- int charge_now, current_now, m, h;
+ uint64_t charge_now, current_now, m, h;
                 double timeleft;
                 char path[PATH_MAX], state[12];
 
_AT_@ -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, "%" PRIu64, &charge_now) < 0) {
                         return NULL;
                 }
 
_AT_@ -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", &current_now) < 0) {
+ pscanf(path, "%" PRIu64, &current_now) < 0) {
                                 return NULL;
                         }
 
_AT_@ -112,7 +113,7 @@
                         h = timeleft;
                         m = (timeleft - (double)h) * 60;
 
- return bprintf("%dh %dm", h, m);
+ return bprintf("%" PRIu64 "h %" PRIu64 "m", h, m);
                 }
 
                 return "";
Received on Sat Jul 07 2018 - 10:32:21 CEST

This archive was generated by hypermail 2.3.0 : Sat Jul 07 2018 - 10:36:25 CEST