#if defined(LINUX)
long int temp;
if (!slurp(path, buf, sizeof(buf)))
- die("Could not open \"%s\"\n", path);
+ goto error;
temp = strtol(buf, NULL, 10);
if (temp == LONG_MIN || temp == LONG_MAX || temp <= 0)
(void)printf("?");
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
int sysctl_rslt;
size_t sysctl_size = sizeof(sysctl_rslt);
- if (sysctlbyname(path, &sysctl_rslt, &sysctl_size, NULL, 0)) {
- (void)printf("No thermal zone found");
- return;
- }
+ if (sysctlbyname(path, &sysctl_rslt, &sysctl_size, NULL, 0))
+ goto error;
(void)printf("%d.%d", TZ_KELVTOC(sysctl_rslt));
#endif
walk += strlen("degrees");
}
}
+ return;
+error:
#endif
+ (void)fputs("Cannot read temperature\n", stderr);
}
#if defined(LINUX)
static char statpath[512];
strcpy(statpath, "/proc/stat");
- if (!slurp(statpath, buf, sizeof(buf)))
- die("could not read %s\n", statpath);
-
- if (sscanf(buf, "cpu %d %d %d %d", &curr_user, &curr_nice, &curr_system, &curr_idle) != 4)
- die("could not read cpu utilization\n");
+ if (!slurp(statpath, buf, sizeof(buf) ||
+ sscanf(buf, "cpu %d %d %d %d", &curr_user, &curr_nice, &curr_system, &curr_idle) != 4))
+ goto error;
curr_total = curr_user + curr_nice + curr_system + curr_idle;
diff_idle = curr_idle - prev_idle;
diff_usage = (1000 * (diff_total - diff_idle)/diff_total + 5)/10;
prev_total = curr_total;
prev_idle = curr_idle;
-#endif
-#if defined(__FreeBSD__)
+#elif defined(__FreeBSD__)
size_t size;
long cp_time[CPUSTATES];
size = sizeof cp_time;
- if (sysctlbyname("kern.cp_time", &cp_time, &size, NULL, 0) < 0){
- return;
- }
+ if (sysctlbyname("kern.cp_time", &cp_time, &size, NULL, 0) < 0)
+ goto error;
+
curr_user = cp_time[CP_USER];
curr_nice = cp_time[CP_NICE];
curr_system = cp_time[CP_SYS];
diff_usage = (1000 * (diff_total - diff_idle)/diff_total + 5)/10;
prev_total = curr_total;
prev_idle = curr_idle;
-
+#else
+ goto error;
#endif
for (walk = format; *walk != '\0'; walk++) {
if (*walk != '%') {
walk += strlen("usage");
}
}
+ return;
+error:
+ (void)fputs("Cannot read usage\n", stderr);
}
// vim:ts=8:expandtab
#include "i3status.h"
-#include <err.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
const char *walk;
if (getloadavg(loadavg, 3) == -1)
- errx(-1, "getloadavg() failed\n");
+ goto error;
for (walk = format; *walk != '\0'; walk++) {
if (*walk != '%') {
walk += strlen("15min");
}
}
+ return;
+error:
#endif
+ (void)fputs("Cannot read load\n", stderr);
}