   /***************************************/
  /*** c0dev0ids lazy ass sdorfehs bar ***/
 /***************************************/
static char * fifo_path = "/home/sdk/.config/sdorfehs/bar";

#include <stdio.h>
//#include <string.h>
//#include <fcntl.h>
//#include <sys/ioctl.h>
//#include <sys/stat.h>
//#include <sys/types.h>
//#include <unistd.h>
//#include <machine/apmvar.h>

char * juice()
{
    int fd;
    char buf[2];
    struct apm_power_info pi;

    if ((fd = open("/dev/apm", O_RDONLY)) == -1 ||
            ioctl(fd, APM_IOC_GETPOWER, &pi) == -1 ||
            close(fd) == -1)
        return "??";

    if (pi.battery_state == APM_BATT_UNKNOWN ||
            pi.battery_state == APM_BATTERY_ABSENT)
        return "??";

    return snprintf(buf, sizeof(buf), "%i", pi.battery_life);
}

int main() {
    int fifo_fd;
    int i = 0;
    while(1) {
        fifo_fd = open(fifo_path, O_NONBLOCK | O_WRONLY);
        char str[255] = "";

        snprintf(str, sizeof(str),  "Battery: %s%%\n",juice());

        write(fifo_fd, str, strlen(str)+1);
        close(fifo_fd);

        sleep(1);
    }
    return 0;
}
