diff options
author | drkhsh <me@drkhsh.at> | 2022-10-28 00:21:02 +0200 |
---|---|---|
committer | Rafael Marçalo <raroma09@gmail.com> | 2022-10-28 22:22:34 +0100 |
commit | 7f00bf6b0b85d23818d6481f771073d82f1dd704 (patch) | |
tree | 8fdef928ebab89ed646b18ca41980ea92d966263 /components | |
parent | 0dfc423e83ea7e609ab63122d8a1e5b3ceed41b5 (diff) |
radical re-formatting 3/3: Error checks
Check for `< 0` instead of `== -1`.
Fixes coding style. Formatting commits suck, incoherent coding style
sucks more.
https://suckless.org/coding_style/
Diffstat (limited to 'components')
-rw-r--r-- | components/cpu.c | 6 | ||||
-rw-r--r-- | components/netspeeds.c | 4 | ||||
-rw-r--r-- | components/ram.c | 20 | ||||
-rw-r--r-- | components/swap.c | 2 |
4 files changed, 15 insertions, 17 deletions
diff --git a/components/cpu.c b/components/cpu.c index 20354c0..6636728 100644 --- a/components/cpu.c +++ b/components/cpu.c @@ -122,8 +122,7 @@ size = sizeof(freq); /* in MHz */ - if (sysctlbyname("hw.clockrate", &freq, &size, NULL, 0) == -1 - || !size) { + if (sysctlbyname("hw.clockrate", &freq, &size, NULL, 0) < 0 || !size) { warn("sysctlbyname 'hw.clockrate':"); return NULL; } @@ -140,8 +139,7 @@ size = sizeof(a); memcpy(b, a, sizeof(b)); - if (sysctlbyname("kern.cp_time", &a, &size, NULL, 0) == -1 - || !size) { + if (sysctlbyname("kern.cp_time", &a, &size, NULL, 0) < 0 || !size) { warn("sysctlbyname 'kern.cp_time':"); return NULL; } diff --git a/components/netspeeds.c b/components/netspeeds.c index 18aa097..e61d982 100644 --- a/components/netspeeds.c +++ b/components/netspeeds.c @@ -75,7 +75,7 @@ oldrxbytes = rxbytes; - if (getifaddrs(&ifal) == -1) { + if (getifaddrs(&ifal) < 0) { warn("getifaddrs failed"); return NULL; } @@ -111,7 +111,7 @@ oldtxbytes = txbytes; - if (getifaddrs(&ifal) == -1) { + if (getifaddrs(&ifal) < 0) { warn("getifaddrs failed"); return NULL; } diff --git a/components/ram.c b/components/ram.c index 518c18c..52f2477 100644 --- a/components/ram.c +++ b/components/ram.c @@ -164,8 +164,8 @@ size_t len; len = sizeof(struct vmtotal); - if (sysctl(mib, 2, &vm_stats, &len, NULL, 0) == -1 - || !len) + if (sysctl(mib, 2, &vm_stats, &len, NULL, 0) < 0 + || !len) return NULL; return fmt_human(vm_stats.t_free * getpagesize(), 1024); @@ -177,8 +177,8 @@ size_t len; len = sizeof(npages); - if (sysctlbyname("vm.stats.vm.v_page_count", &npages, &len, NULL, 0) == -1 - || !len) + if (sysctlbyname("vm.stats.vm.v_page_count", + &npages, &len, NULL, 0) < 0 || !len) return NULL; return fmt_human(npages * getpagesize(), 1024); @@ -191,12 +191,12 @@ size_t len; len = sizeof(npages); - if (sysctlbyname("vm.stats.vm.v_page_count", &npages, &len, NULL, 0) == -1 - || !len) + if (sysctlbyname("vm.stats.vm.v_page_count", + &npages, &len, NULL, 0) < 0 || !len) return NULL; - if (sysctlbyname("vm.stats.vm.v_active_count", &active, &len, NULL, 0) == -1 - || !len) + if (sysctlbyname("vm.stats.vm.v_active_count", + &active, &len, NULL, 0) < 0 || !len) return NULL; return bprintf("%d", active * 100 / npages); @@ -208,8 +208,8 @@ size_t len; len = sizeof(active); - if (sysctlbyname("vm.stats.vm.v_active_count", &active, &len, NULL, 0) == -1 - || !len) + if (sysctlbyname("vm.stats.vm.v_active_count", + &active, &len, NULL, 0) < 0 || !len) return NULL; return fmt_human(active * getpagesize(), 1024); diff --git a/components/swap.c b/components/swap.c index 49ba3cb..523d9cd 100644 --- a/components/swap.c +++ b/components/swap.c @@ -215,7 +215,7 @@ return 0; } - if(kvm_getswapinfo(kd, swap_info, size, 0 /* Unused flags */) == -1) { + if (kvm_getswapinfo(kd, swap_info, size, 0 /* Unused flags */) < 0) { warn("kvm_getswapinfo:"); kvm_close(kd); return 0; |