Xinqi Bao's Git
projects
/
slstatus.git
/ blobdiff
summary
|
log
|
commit
|
diff
|
tree
raw
|
inline
| side by side
Set {r,t}xbytes 0 before incrementing them on OBSD
[slstatus.git]
/
components
/
battery.c
diff --git
a/components/battery.c
b/components/battery.c
index
c7c402a
..
b086a28
100644
(file)
--- a/
components/battery.c
+++ b/
components/battery.c
@@
-5,6
+5,14
@@
#include "../util.h"
#include "../util.h"
+static struct {
+ char *state;
+ char *symbol;
+} map[] = {
+ { "Charging", "+" },
+ { "Discharging", "-" },
+};
+
#if defined(__linux__)
#include <limits.h>
#if defined(__linux__)
#include <limits.h>
@@
-16,19
+24,12
@@
snprintf(path, sizeof(path), "%s%s%s", "/sys/class/power_supply/",
bat, "/capacity");
snprintf(path, sizeof(path), "%s%s%s", "/sys/class/power_supply/",
bat, "/capacity");
- return (pscanf(path, "%
i
", &perc) == 1) ? bprintf("%d", perc) : NULL;
+ return (pscanf(path, "%
d
", &perc) == 1) ? bprintf("%d", perc) : NULL;
}
const char *
battery_state(const char *bat)
{
}
const char *
battery_state(const char *bat)
{
- struct {
- char *state;
- char *symbol;
- } map[] = {
- { "Charging", "+" },
- { "Discharging", "-" },
- };
size_t i;
char path[PATH_MAX], state[12];
size_t i;
char path[PATH_MAX], state[12];
@@
-62,12
+63,12
@@
if (!strcmp(state, "Discharging")) {
snprintf(path, sizeof(path), "%s%s%s", "/sys/class/power_supply/",
bat, "/charge_now");
if (!strcmp(state, "Discharging")) {
snprintf(path, sizeof(path), "%s%s%s", "/sys/class/power_supply/",
bat, "/charge_now");
- if (pscanf(path, "%
i
", &charge_now) != 1) {
+ if (pscanf(path, "%
d
", &charge_now) != 1) {
return NULL;
}
snprintf(path, sizeof(path), "%s%s%s", "/sys/class/power_supply/",
bat, "/current_now");
return NULL;
}
snprintf(path, sizeof(path), "%s%s%s", "/sys/class/power_supply/",
bat, "/current_now");
- if (pscanf(path, "%
i
", ¤t_now) != 1) {
+ if (pscanf(path, "%
d
", ¤t_now) != 1) {
return NULL;
}
return NULL;
}
@@
-123,13
+124,6
@@
{
struct apm_power_info apm_info;
size_t i;
{
struct apm_power_info apm_info;
size_t i;
- struct {
- unsigned int state;
- char *symbol;
- } map[] = {
- { APM_AC_ON, "+" },
- { APM_AC_OFF, "-" },
- };
if (load_apm_power_info(&apm_info)) {
for (i = 0; i < LEN(map); i++) {
if (load_apm_power_info(&apm_info)) {
for (i = 0; i < LEN(map); i++) {