Skip to content

Commit d76b1a2

Browse files
committed
battery: 64 bit ints on Linux
1 parent b792b7a commit d76b1a2

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Diff for: components/battery.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "../util.h"
66

77
#if defined(__linux__)
8+
#include <inttypes.h>
89
#include <limits.h>
910
#include <unistd.h>
1011

@@ -76,7 +77,7 @@
7677
const char *
7778
battery_remaining(const char *bat)
7879
{
79-
int charge_now, current_now, m, h;
80+
uint64_t charge_now, current_now, m, h;
8081
double timeleft;
8182
char path[PATH_MAX], state[12];
8283

@@ -92,15 +93,15 @@
9293
if (!pick(bat, "/sys/class/power_supply/%s/charge_now",
9394
"/sys/class/power_supply/%s/energy_now",
9495
path, sizeof(path)) ||
95-
pscanf(path, "%d", &charge_now) < 0) {
96+
pscanf(path, "%" PRIu64, &charge_now) < 0) {
9697
return NULL;
9798
}
9899

99100
if (!strcmp(state, "Discharging")) {
100101
if (!pick(bat, "/sys/class/power_supply/%s/current_now",
101102
"/sys/class/power_supply/%s/power_now", path,
102103
sizeof(path)) ||
103-
pscanf(path, "%d", &current_now) < 0) {
104+
pscanf(path, "%" PRIu64, &current_now) < 0) {
104105
return NULL;
105106
}
106107

@@ -112,7 +113,7 @@
112113
h = timeleft;
113114
m = (timeleft - (double)h) * 60;
114115

115-
return bprintf("%dh %dm", h, m);
116+
return bprintf("%" PRIu64 "h %" PRIu64 "m", h, m);
116117
}
117118

118119
return "";

0 commit comments

Comments
 (0)