diff options
| -rw-r--r-- | main.c | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -90,28 +90,31 @@ static int isdir(const char *path) static void print_battery_status(void) { -#define PRINT(...) str += snprintf(str, sizeof(status) - (str - status), __VA_ARGS__) - - static char status[512]; - - char *str = status; + char status[512]; + FILE *fp; if (! isdir(SYSPATH)) return; + fp = fmemopen(status, sizeof(status), "w"); + if (! strcasecmp("charging", readline(SYSPATH, "status"))) - PRINT("%s ", charging); + fprintf(fp, "%s ", charging); int capacity = atoi(readline(SYSPATH, "capacity")); if (capacity == 100) - PRINT("full"); + fprintf(fp, "full"); else - PRINT("%d%%", capacity); + fprintf(fp, "%d%%", capacity); + + fflush(fp); printf(", bat: %s", status); readline(NULL, NULL); + + fclose(fp); } static bool is_proc_entry(struct dirent *de) |
