Return "no battery" instead of dying if a battery wasn’t found (Thanks Mirko)
This commit is contained in:
parent
94911d4cc3
commit
f8be2d1b81
@ -50,7 +50,7 @@ void create_file(const char *name);
|
|||||||
char *order_to_str(int number, char *name);
|
char *order_to_str(int number, char *name);
|
||||||
void setup(void);
|
void setup(void);
|
||||||
void write_to_statusbar(const char *name, const char *message, bool final_entry);
|
void write_to_statusbar(const char *name, const char *message, bool final_entry);
|
||||||
void slurp(char *filename, char *destination, int size);
|
bool slurp(char *filename, char *destination, int size);
|
||||||
|
|
||||||
/* src/output.c */
|
/* src/output.c */
|
||||||
void write_error_to_statusbar(const char *message);
|
void write_error_to_statusbar(const char *message);
|
||||||
|
@ -13,14 +13,16 @@
|
|||||||
* Reads size bytes into the destination buffer from filename.
|
* 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;
|
int fd;
|
||||||
|
|
||||||
if ((fd = open(filename, O_RDONLY)) == -1)
|
if ((fd = open(filename, O_RDONLY)) == -1)
|
||||||
die("Could not open \"%s\"\n", filename);
|
return false;
|
||||||
|
|
||||||
(void)read(fd, destination, size);
|
(void)read(fd, destination, size);
|
||||||
(void)close(fd);
|
(void)close(fd);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -26,7 +26,8 @@ const char *get_battery_info(struct battery *bat) {
|
|||||||
charging_status_t status = CS_DISCHARGING;
|
charging_status_t status = CS_DISCHARGING;
|
||||||
|
|
||||||
#if defined(LINUX)
|
#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++) {
|
for (walk = buf, last = buf; (walk-buf) < 1024; walk++) {
|
||||||
if (*walk == '\n') {
|
if (*walk == '\n') {
|
||||||
|
@ -24,7 +24,8 @@ const char *get_cpu_temperature_info() {
|
|||||||
|
|
||||||
#if defined(LINUX)
|
#if defined(LINUX)
|
||||||
long int temp;
|
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);
|
temp = strtol(buf, NULL, 10);
|
||||||
if (temp == LONG_MIN || temp == LONG_MAX || temp <= 0)
|
if (temp == LONG_MIN || temp == LONG_MAX || temp <= 0)
|
||||||
(void)snprintf(buf, sizeof(buf), "T: ? C");
|
(void)snprintf(buf, sizeof(buf), "T: ? C");
|
||||||
|
@ -20,7 +20,8 @@ const char *get_wireless_info() {
|
|||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
memset(part, 0, sizeof(part));
|
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;
|
interfaces = skip_character(buf, '\n', 1) + 1;
|
||||||
while ((interfaces = skip_character(interfaces, '\n', 1)+1) < buf+strlen(buf)) {
|
while ((interfaces = skip_character(interfaces, '\n', 1)+1) < buf+strlen(buf)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user