fix: stop segfaulting on non-existent directories

This commit is contained in:
2025-09-26 16:40:27 -04:00
parent ee6dfc9ac6
commit afa4e48757
4 changed files with 50 additions and 15 deletions

View File

@@ -3,6 +3,7 @@
#include <stdbool.h>
#include <unistd.h>
#include "log.h"
#include "utils.h"
#include "config.h"
@@ -17,6 +18,10 @@ char
/* open up the battery capacity for reading */
d = concat(battery_status_path, "/capacity");
f = fopen(d, "r");
if (!f) {
log_fatal("battery directory does not exist");
return NULL;
}
free(d);
/* create enough space for the battery percentage */