mirror of
https://github.com/pikami/slstatus.git
synced 2024-11-27 05:45:42 +00:00
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/
This commit is contained in:
parent
3251e91187
commit
cce2e5ecb0
@ -118,8 +118,7 @@
|
|||||||
|
|
||||||
size = sizeof(freq);
|
size = sizeof(freq);
|
||||||
/* in MHz */
|
/* in MHz */
|
||||||
if (sysctlbyname("hw.clockrate", &freq, &size, NULL, 0) == -1
|
if (sysctlbyname("hw.clockrate", &freq, &size, NULL, 0) < 0 || !size) {
|
||||||
|| !size) {
|
|
||||||
warn("sysctlbyname 'hw.clockrate':");
|
warn("sysctlbyname 'hw.clockrate':");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -136,8 +135,7 @@
|
|||||||
|
|
||||||
size = sizeof(a);
|
size = sizeof(a);
|
||||||
memcpy(b, a, sizeof(b));
|
memcpy(b, a, sizeof(b));
|
||||||
if (sysctlbyname("kern.cp_time", &a, &size, NULL, 0) == -1
|
if (sysctlbyname("kern.cp_time", &a, &size, NULL, 0) < 0 || !size) {
|
||||||
|| !size) {
|
|
||||||
warn("sysctlbyname 'kern.cp_time':");
|
warn("sysctlbyname 'kern.cp_time':");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@
|
|||||||
|
|
||||||
oldrxbytes = rxbytes;
|
oldrxbytes = rxbytes;
|
||||||
|
|
||||||
if (getifaddrs(&ifal) == -1) {
|
if (getifaddrs(&ifal) < 0) {
|
||||||
warn("getifaddrs failed");
|
warn("getifaddrs failed");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -105,7 +105,7 @@
|
|||||||
|
|
||||||
oldtxbytes = txbytes;
|
oldtxbytes = txbytes;
|
||||||
|
|
||||||
if (getifaddrs(&ifal) == -1) {
|
if (getifaddrs(&ifal) < 0) {
|
||||||
warn("getifaddrs failed");
|
warn("getifaddrs failed");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -159,8 +159,8 @@
|
|||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
len = sizeof(struct vmtotal);
|
len = sizeof(struct vmtotal);
|
||||||
if (sysctl(mib, 2, &vm_stats, &len, NULL, 0) == -1
|
if (sysctl(mib, 2, &vm_stats, &len, NULL, 0) < 0
|
||||||
|| !len)
|
|| !len)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return fmt_human(vm_stats.t_free * getpagesize(), 1024);
|
return fmt_human(vm_stats.t_free * getpagesize(), 1024);
|
||||||
@ -172,8 +172,8 @@
|
|||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
len = sizeof(npages);
|
len = sizeof(npages);
|
||||||
if (sysctlbyname("vm.stats.vm.v_page_count", &npages, &len, NULL, 0) == -1
|
if (sysctlbyname("vm.stats.vm.v_page_count",
|
||||||
|| !len)
|
&npages, &len, NULL, 0) < 0 || !len)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return fmt_human(npages * getpagesize(), 1024);
|
return fmt_human(npages * getpagesize(), 1024);
|
||||||
@ -186,12 +186,12 @@
|
|||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
len = sizeof(npages);
|
len = sizeof(npages);
|
||||||
if (sysctlbyname("vm.stats.vm.v_page_count", &npages, &len, NULL, 0) == -1
|
if (sysctlbyname("vm.stats.vm.v_page_count",
|
||||||
|| !len)
|
&npages, &len, NULL, 0) < 0 || !len)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (sysctlbyname("vm.stats.vm.v_active_count", &active, &len, NULL, 0) == -1
|
if (sysctlbyname("vm.stats.vm.v_active_count",
|
||||||
|| !len)
|
&active, &len, NULL, 0) < 0 || !len)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return bprintf("%d", active * 100 / npages);
|
return bprintf("%d", active * 100 / npages);
|
||||||
@ -203,8 +203,8 @@
|
|||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
len = sizeof(active);
|
len = sizeof(active);
|
||||||
if (sysctlbyname("vm.stats.vm.v_active_count", &active, &len, NULL, 0) == -1
|
if (sysctlbyname("vm.stats.vm.v_active_count",
|
||||||
|| !len)
|
&active, &len, NULL, 0) < 0 || !len)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return fmt_human(active * getpagesize(), 1024);
|
return fmt_human(active * getpagesize(), 1024);
|
||||||
|
@ -204,7 +204,7 @@
|
|||||||
return 0;
|
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:");
|
warn("kvm_getswapinfo:");
|
||||||
kvm_close(kd);
|
kvm_close(kd);
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user