7 #include <sys/statvfs.h>
12 #define TERABYTE (1024ULL * 1024 * 1024 * 1024)
13 #define GIGABYTE (1024ULL * 1024 * 1024)
14 #define MEGABYTE (1024ULL * 1024)
15 #define KILOBYTE (1024ULL)
17 void print_bytes_human(uint64_t bytes) {
20 printf("%f TB", (double)bytes / TERABYTE);
21 else if (bytes > GIGABYTE)
22 printf("%.01f GB", (double)bytes / GIGABYTE);
23 else if (bytes > MEGABYTE)
24 printf("%.01f MB", (double)bytes / MEGABYTE);
25 else if (bytes > KILOBYTE)
26 printf("%.01f KB", (double)bytes / KILOBYTE);
28 printf("%.01f B", (double)bytes);
34 * Just parses /proc/net/wireless looking for lines beginning with
35 * wlan_interface, extracting the quality of the link and adding the
36 * current IP address of wlan_interface.
39 void print_disk_info(const char *path, const char *format) {
43 if (statvfs(path, &buf) == -1)
46 for (walk = format; *walk != '\0'; walk++) {
52 if (BEGINS_WITH(walk+1, "free")) {
53 print_bytes_human(buf.f_bsize * buf.f_bfree);
54 walk += strlen("free");
57 if (BEGINS_WITH(walk+1, "used")) {
58 print_bytes_human(buf.f_bsize * (buf.f_blocks - buf.f_bfree));
59 walk += strlen("used");
62 if (BEGINS_WITH(walk+1, "total")) {
63 print_bytes_human(buf.f_bsize * buf.f_blocks);
64 walk += strlen("total");