diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/general.c | 6 | ||||
-rw-r--r-- | src/get_battery_info.c | 3 | ||||
-rw-r--r-- | src/get_cpu_temperature.c | 3 | ||||
-rw-r--r-- | src/get_wireless_info.c | 3 |
4 files changed, 10 insertions, 5 deletions
diff --git a/src/general.c b/src/general.c index 62d242d..8d48f74 100644 --- a/src/general.c +++ b/src/general.c @@ -13,14 +13,16 @@ * Reads size bytes into the destination buffer from filename. * */ -void slurp(char *filename, char *destination, int size) { +bool slurp(char *filename, char *destination, int size) { int fd; if ((fd = open(filename, O_RDONLY)) == -1) - die("Could not open \"%s\"\n", filename); + return false; (void)read(fd, destination, size); (void)close(fd); + + return true; } /* diff --git a/src/get_battery_info.c b/src/get_battery_info.c index 8ac7743..41f2ff3 100644 --- a/src/get_battery_info.c +++ b/src/get_battery_info.c @@ -26,7 +26,8 @@ const char *get_battery_info(struct battery *bat) { charging_status_t status = CS_DISCHARGING; #if defined(LINUX) - slurp(bat->path, buf, sizeof(buf)); + if (!slurp(bat->path, buf, sizeof(buf))) + return "No battery"; for (walk = buf, last = buf; (walk-buf) < 1024; walk++) { if (*walk == '\n') { diff --git a/src/get_cpu_temperature.c b/src/get_cpu_temperature.c index 09fbd25..ca6b9df 100644 --- a/src/get_cpu_temperature.c +++ b/src/get_cpu_temperature.c @@ -24,7 +24,8 @@ const char *get_cpu_temperature_info() { #if defined(LINUX) long int temp; - slurp(thermal_zone, buf, sizeof(buf)); + if (!slurp(thermal_zone, buf, sizeof(buf))) + die("Could not open \"%s\"\n", thermal_zone); temp = strtol(buf, NULL, 10); if (temp == LONG_MIN || temp == LONG_MAX || temp <= 0) (void)snprintf(buf, sizeof(buf), "T: ? C"); diff --git a/src/get_wireless_info.c b/src/get_wireless_info.c index 4d8d0b2..c257f56 100644 --- a/src/get_wireless_info.c +++ b/src/get_wireless_info.c @@ -20,7 +20,8 @@ const char *get_wireless_info() { memset(buf, 0, sizeof(buf)); memset(part, 0, sizeof(part)); - slurp("/proc/net/wireless", buf, sizeof(buf)); + if (!slurp("/proc/net/wireless", buf, sizeof(buf))) + die("Could not open \"/proc/net/wireless\"\n"); interfaces = skip_character(buf, '\n', 1) + 1; while ((interfaces = skip_character(interfaces, '\n', 1)+1) < buf+strlen(buf)) { |