battery: Separate function for readbility

This commit is contained in:
Aaron Marcher 2018-04-29 20:02:42 +02:00
parent cee6811036
commit 09950055ba

View File

@ -14,17 +14,21 @@
#include "../util.h" #include "../util.h"
#if defined(__linux__)
const char * const char *
battery_perc(const char *bat) battery_perc(const char *bat)
{ {
#if defined(__linux__)
int perc; int perc;
char path[PATH_MAX]; char path[PATH_MAX];
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) ? return (pscanf(path, "%i", &perc) == 1) ?
bprintf("%d", perc) : NULL; bprintf("%d", perc) : NULL;
}
#elif defined(__OpenBSD__) #elif defined(__OpenBSD__)
const char *
battery_perc(const char *null)
{
struct apm_power_info apm_info; struct apm_power_info apm_info;
int fd; int fd;
@ -42,8 +46,8 @@ battery_perc(const char *bat)
close(fd); close(fd);
return bprintf("%d", apm_info.battery_life); return bprintf("%d", apm_info.battery_life);
#endif
} }
#endif
#if defined(__linux__) #if defined(__linux__)
const char * const char *