X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fprint_disk_info.c;h=12d75857cf8dce882a19521d9726473877c9f972;hb=a13b2e7288e943359ccb37be86efb716efbe98c8;hp=b9047e5388e9baa465cd23f334fbdf9755c7f9a9;hpb=5cdbb3045b4524d12f310c4c040a09489fefb57b;p=i3%2Fi3status diff --git a/src/print_disk_info.c b/src/print_disk_info.c index b9047e5..12d7585 100644 --- a/src/print_disk_info.c +++ b/src/print_disk_info.c @@ -3,14 +3,15 @@ #include #include #include -#include #include #include #include #include -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || (__OpenBSD__) || defined(__DragonFly__) +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || (__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__) #include #include +#else +#include #endif #include #include @@ -58,7 +59,7 @@ static int print_bytes_human(char *outwalk, uint64_t bytes, const char *prefix_t * Determines whether remaining bytes are below given threshold. * */ -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) || defined(__DragonFly__) +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__) static bool below_threshold(struct statfs buf, const char *prefix_type, const char *threshold_type, const double low_threshold) { #else static bool below_threshold(struct statvfs buf, const char *prefix_type, const char *threshold_type, const double low_threshold) { @@ -115,7 +116,7 @@ void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const ch INSTANCE(path); -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) || defined(__DragonFly__) +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__) struct statfs buf; if (statfs(path, &buf) == -1) @@ -123,10 +124,11 @@ void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const ch #else struct statvfs buf; - if (statvfs(path, &buf) == -1) - return; - - if (format_not_mounted != NULL) { + if (statvfs(path, &buf) == -1) { + /* If statvfs errors, e.g., due to the path not existing, + * we use the format for a not mounted device. */ + format = format_not_mounted; + } else if (format_not_mounted != NULL) { FILE *mntentfile = setmntent("/etc/mtab", "r"); struct mntent *m; bool found = false; @@ -177,22 +179,22 @@ void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const ch } if (BEGINS_WITH(walk + 1, "percentage_free")) { - outwalk += sprintf(outwalk, "%.01f%%", 100.0 * (double)buf.f_bfree / (double)buf.f_blocks); + outwalk += sprintf(outwalk, "%.01f%s", 100.0 * (double)buf.f_bfree / (double)buf.f_blocks, pct_mark); walk += strlen("percentage_free"); } if (BEGINS_WITH(walk + 1, "percentage_used_of_avail")) { - outwalk += sprintf(outwalk, "%.01f%%", 100.0 * (double)(buf.f_blocks - buf.f_bavail) / (double)buf.f_blocks); + outwalk += sprintf(outwalk, "%.01f%s", 100.0 * (double)(buf.f_blocks - buf.f_bavail) / (double)buf.f_blocks, pct_mark); walk += strlen("percentage_used_of_avail"); } if (BEGINS_WITH(walk + 1, "percentage_used")) { - outwalk += sprintf(outwalk, "%.01f%%", 100.0 * (double)(buf.f_blocks - buf.f_bfree) / (double)buf.f_blocks); + outwalk += sprintf(outwalk, "%.01f%s", 100.0 * (double)(buf.f_blocks - buf.f_bfree) / (double)buf.f_blocks, pct_mark); walk += strlen("percentage_used"); } if (BEGINS_WITH(walk + 1, "percentage_avail")) { - outwalk += sprintf(outwalk, "%.01f%%", 100.0 * (double)buf.f_bavail / (double)buf.f_blocks); + outwalk += sprintf(outwalk, "%.01f%s", 100.0 * (double)buf.f_bavail / (double)buf.f_blocks, pct_mark); walk += strlen("percentage_avail"); } }