slstatus

Fork of suckless' slstatus with my personal patches
git clone https://git.instinctive.eu/slstatus.git
Log | Files | Refs | README | LICENSE

commit 0c2b3e5b5c499b1de566fd4bef49c5e6b5254d1a
parent 28ef0b242c32e8ae8b4df2b4b380e30bf581130f
Author: NRK <nrk@disroot.org>
Date:   Thu, 27 Oct 2022 02:16:05 +0600

do not rely on obsolete feature

function prototype with unspecified argument is obsolete since c99.

additionally some of these function which don't take any argument were
being called with a `const char *` arg, which is UB.

fix both these issues by declararing ALL the components to accept a
`const char *`, and name the arg "unused" if it's meant to be ignored.

Diffstat:
Mcomponents/cpu.c | 12++++++------
Mcomponents/entropy.c | 4++--
Mcomponents/hostname.c | 2+-
Mcomponents/kernel_release.c | 2+-
Mcomponents/keymap.c | 2+-
Mcomponents/load_avg.c | 2+-
Mcomponents/ram.c | 24++++++++++++------------
Mcomponents/swap.c | 24++++++++++++------------
Mcomponents/uptime.c | 2+-
Mcomponents/user.c | 6+++---
Mconfig.mk | 2+-
Mslstatus.c | 2+-
Mslstatus.h | 38+++++++++++++++++++-------------------
13 files changed, 61 insertions(+), 61 deletions(-)

diff --git a/components/cpu.c b/components/cpu.c @@ -8,7 +8,7 @@ #if defined(__linux__) const char * - cpu_freq(void) + cpu_freq(const char *unused) { uintmax_t freq; @@ -22,7 +22,7 @@ } const char * - cpu_perc(void) + cpu_perc(const char *unused) { static long double a[7]; long double b[7], sum; @@ -55,7 +55,7 @@ #include <sys/sysctl.h> const char * - cpu_freq(void) + cpu_freq(const char *unused) { int freq, mib[2]; size_t size; @@ -75,7 +75,7 @@ } const char * - cpu_perc(void) + cpu_perc(const char *unused) { int mib[2]; static uintmax_t a[CPUSTATES]; @@ -115,7 +115,7 @@ #include <devstat.h> const char * - cpu_freq(void) + cpu_freq(const char *unused) { int freq; size_t size; @@ -132,7 +132,7 @@ } const char * - cpu_perc(void) + cpu_perc(const char *unused) { size_t size; static long a[CPUSTATES]; diff --git a/components/entropy.c b/components/entropy.c @@ -7,7 +7,7 @@ #include "../util.h" const char * - entropy(void) + entropy(const char *unused) { uintmax_t num; @@ -20,7 +20,7 @@ } #elif defined(__OpenBSD__) | defined(__FreeBSD__) const char * - entropy(void) + entropy(const char *unused) { /* Unicode Character 'INFINITY' (U+221E) */ return "\xe2\x88\x9e"; diff --git a/components/hostname.c b/components/hostname.c @@ -6,7 +6,7 @@ #include "../slstatus.h" const char * -hostname(void) +hostname(const char *unused) { if (gethostname(buf, sizeof(buf)) < 0) { warn("gethostbyname:"); diff --git a/components/kernel_release.c b/components/kernel_release.c @@ -6,7 +6,7 @@ #include "../slstatus.h" const char * -kernel_release(void) +kernel_release(const char *unused) { struct utsname udata; diff --git a/components/keymap.c b/components/keymap.c @@ -47,7 +47,7 @@ get_layout(char *syms, int grp_num) } const char * -keymap(void) +keymap(const char *unused) { Display *dpy; XkbDescRec *desc; diff --git a/components/load_avg.c b/components/load_avg.c @@ -6,7 +6,7 @@ #include "../slstatus.h" const char * -load_avg(void) +load_avg(const char *unused) { double avgs[3]; diff --git a/components/ram.c b/components/ram.c @@ -8,7 +8,7 @@ #include <stdint.h> const char * - ram_free(void) + ram_free(const char *unused) { uintmax_t free; @@ -24,7 +24,7 @@ } const char * - ram_perc(void) + ram_perc(const char *unused) { uintmax_t total, free, buffers, cached; @@ -47,7 +47,7 @@ } const char * - ram_total(void) + ram_total(const char *unused) { uintmax_t total; @@ -60,7 +60,7 @@ } const char * - ram_used(void) + ram_used(const char *unused) { uintmax_t total, free, buffers, cached; @@ -102,7 +102,7 @@ } const char * - ram_free(void) + ram_free(const char *unused) { struct uvmexp uvmexp; int free_pages; @@ -117,7 +117,7 @@ } const char * - ram_perc(void) + ram_perc(const char *unused) { struct uvmexp uvmexp; int percent; @@ -131,7 +131,7 @@ } const char * - ram_total(void) + ram_total(const char *unused) { struct uvmexp uvmexp; @@ -145,7 +145,7 @@ } const char * - ram_used(void) + ram_used(const char *unused) { struct uvmexp uvmexp; @@ -164,7 +164,7 @@ #include <vm/vm_param.h> const char * - ram_free(void) { + ram_free(const char *unused) { struct vmtotal vm_stats; int mib[] = {CTL_VM, VM_TOTAL}; size_t len; @@ -178,7 +178,7 @@ } const char * - ram_total(void) { + ram_total(const char *unused) { unsigned int npages; size_t len; @@ -191,7 +191,7 @@ } const char * - ram_perc(void) { + ram_perc(const char *unused) { unsigned int npages; unsigned int active; size_t len; @@ -209,7 +209,7 @@ } const char * - ram_used(void) { + ram_used(const char *unused) { unsigned int active; size_t len; diff --git a/components/swap.c b/components/swap.c @@ -59,7 +59,7 @@ } const char * - swap_free(void) + swap_free(const char *unused) { long free; @@ -71,7 +71,7 @@ } const char * - swap_perc(void) + swap_perc(const char *unused) { long total, free, cached; @@ -83,7 +83,7 @@ } const char * - swap_total(void) + swap_total(const char *unused) { long total; @@ -95,7 +95,7 @@ } const char * - swap_used(void) + swap_used(const char *unused) { long total, free, cached; @@ -148,7 +148,7 @@ } const char * - swap_free(void) + swap_free(const char *unused) { int total, used; @@ -160,7 +160,7 @@ } const char * - swap_perc(void) + swap_perc(const char *unused) { int total, used; @@ -176,7 +176,7 @@ } const char * - swap_total(void) + swap_total(const char *unused) { int total, used; @@ -188,7 +188,7 @@ } const char * - swap_used(void) + swap_used(const char *unused) { int total, used; @@ -226,7 +226,7 @@ } const char * - swap_free(void) + swap_free(const char *unused) { struct kvm_swap swap_info[1]; long used, total; @@ -241,7 +241,7 @@ } const char * - swap_perc(void) + swap_perc(const char *unused) { struct kvm_swap swap_info[1]; long used, total; @@ -256,7 +256,7 @@ } const char * - swap_total(void) + swap_total(const char *unused) { struct kvm_swap swap_info[1]; long total; @@ -270,7 +270,7 @@ } const char * - swap_used(void) + swap_used(const char *unused) { struct kvm_swap swap_info[1]; long used; diff --git a/components/uptime.c b/components/uptime.c @@ -15,7 +15,7 @@ #endif const char * -uptime(void) +uptime(const char *unused) { char warn_buf[256]; uintmax_t h, m; diff --git a/components/user.c b/components/user.c @@ -8,13 +8,13 @@ #include "../slstatus.h" const char * -gid(void) +gid(const char *unused) { return bprintf("%d", getgid()); } const char * -username(void) +username(const char *unused) { struct passwd *pw; @@ -27,7 +27,7 @@ username(void) } const char * -uid(void) +uid(const char *unused) { return bprintf("%d", geteuid()); } diff --git a/config.mk b/config.mk @@ -12,7 +12,7 @@ X11LIB = /usr/X11R6/lib # flags CPPFLAGS = -I$(X11INC) -D_DEFAULT_SOURCE -CFLAGS = -std=c99 -pedantic -Wall -Wextra -Os +CFLAGS = -std=c99 -pedantic -Wall -Wextra -Wno-unused-parameter -Os LDFLAGS = -L$(X11LIB) -s # OpenBSD: add -lsndio # FreeBSD: add -lkvm -lsndio diff --git a/slstatus.c b/slstatus.c @@ -12,7 +12,7 @@ #include "util.h" struct arg { - const char *(*func)(); + const char *(*func)(const char *); const char *fmt; const char *args; }; diff --git a/slstatus.h b/slstatus.h @@ -6,8 +6,8 @@ const char *battery_state(const char *); const char *battery_remaining(const char *); /* cpu */ -const char *cpu_freq(void); -const char *cpu_perc(void); +const char *cpu_freq(const char *unused); +const char *cpu_perc(const char *unused); /* datetime */ const char *datetime(const char *fmt); @@ -19,26 +19,26 @@ const char *disk_total(const char *path); const char *disk_used(const char *path); /* entropy */ -const char *entropy(void); +const char *entropy(const char *unused); /* hostname */ -const char *hostname(void); +const char *hostname(const char *unused); /* ip */ const char *ipv4(const char *interface); const char *ipv6(const char *interface); /* kernel_release */ -const char *kernel_release(void); +const char *kernel_release(const char *unused); /* keyboard_indicators */ const char *keyboard_indicators(const char *fmt); /* keymap */ -const char *keymap(void); +const char *keymap(const char *unused); /* load_avg */ -const char *load_avg(void); +const char *load_avg(const char *unused); /* netspeeds */ const char *netspeed_rx(const char *interface); @@ -48,10 +48,10 @@ const char *netspeed_tx(const char *interface); const char *num_files(const char *path); /* ram */ -const char *ram_free(void); -const char *ram_perc(void); -const char *ram_total(void); -const char *ram_used(void); +const char *ram_free(const char *unused); +const char *ram_perc(const char *unused); +const char *ram_total(const char *unused); +const char *ram_used(const char *unused); /* run_command */ const char *run_command(const char *cmd); @@ -60,21 +60,21 @@ const char *run_command(const char *cmd); const char *separator(const char *separator); /* swap */ -const char *swap_free(void); -const char *swap_perc(void); -const char *swap_total(void); -const char *swap_used(void); +const char *swap_free(const char *unused); +const char *swap_perc(const char *unused); +const char *swap_total(const char *unused); +const char *swap_used(const char *unused); /* temperature */ const char *temp(const char *); /* uptime */ -const char *uptime(void); +const char *uptime(const char *unused); /* user */ -const char *gid(void); -const char *username(void); -const char *uid(void); +const char *gid(const char *unused); +const char *username(const char *unused); +const char *uid(const char *unused); /* volume */ const char *vol_perc(const char *card);