status

statusbar program for dwm
git clone anongit@rnpnr.xyz:status.git
Log | Files | Refs | Feed | README | LICENSE

Commit: 05432449a85f27521f04a6dfbeecba9c7ab34c2b
Parent: 42d31f4796d214139b77765c26e75ce9176b9cc0
Author: Randy Palamar
Date:   Tue, 30 Mar 2021 12:57:02 -0600

remove bprintf()

it used to serve a purpose but now it just wraps snprintf()

Diffstat:
Mblocks/battery.c | 14+++++++-------
Mblocks/mpd.c | 9+++++----
Mblocks/volume.c | 8++++----
Mutil.c | 13-------------
Mutil.h | 1-
5 files changed, 16 insertions(+), 29 deletions(-)

diff --git a/blocks/battery.c b/blocks/battery.c @@ -39,11 +39,11 @@ batinfo(struct Block *b) h = timeleft; m = (timeleft - (double)h) * 60; - bprintf(buf, sizeof(buf), "%d%% (%d:%02d)", perc, h, m); + snprintf(buf, sizeof(buf), "%d%% (%d:%02d)", perc, h, m); } else - bprintf(buf, sizeof(buf), "%d%% (%s)", perc, state); + snprintf(buf, sizeof(buf), "%d%% (%s)", perc, state); - return bprintf(b->curstr, BLOCKLEN, b->fmt, buf); + return snprintf(b->curstr, BLOCKLEN, b->fmt, buf); } #elif defined(__OpenBSD__) @@ -69,14 +69,14 @@ batinfo(struct Block *b) switch (pi.ac_state) { case APM_AC_OFF: - bprintf(buf, sizeof(buf), "%d%% (%d:%02d)", pi.battery_life, + snprintf(buf, sizeof(buf), "%d%% (%d:%02d)", pi.battery_life, pi.minutes_left / 60, pi.minutes_left % 60); case APM_AC_ON: case APM_BATT_CHARGING: - bprintf(buf, sizeof(buf), "%d%% (ac)", pi.battery_life); + snprintf(buf, sizeof(buf), "%d%% (ac)", pi.battery_life); default: - bprintf(buf, sizeof(buf), "%d%% (unknown)", pi.battery_life); + snprintf(buf, sizeof(buf), "%d%% (unknown)", pi.battery_life); } - return bprintf(b->curstr, BLOCKLEN, b->fmt, buf); + return snprintf(b->curstr, BLOCKLEN, b->fmt, buf); } #endif diff --git a/blocks/mpd.c b/blocks/mpd.c @@ -1,5 +1,6 @@ /* See LICENSE for license details. */ #include <mpd/client.h> +#include <stdio.h> #include "../status.h" #include "../util.h" @@ -14,7 +15,7 @@ mpd(struct Block *b) conn = mpd_connection_new(mpdhost, 0, 600); if (!conn || mpd_connection_get_error(conn)) - return bprintf(b->curstr, BLOCKLEN, b->fmt, ""); + return snprintf(b->curstr, BLOCKLEN, b->fmt, ""); mpd_command_list_begin(conn, true); mpd_send_status(conn); @@ -27,16 +28,16 @@ mpd(struct Block *b) if (status && (mpd_status_get_state(status) >= MPD_STATE_PLAY)) { mpd_response_next(conn); song = mpd_recv_song(conn); - bprintf(buf, sizeof(buf), "%s", + snprintf(buf, sizeof(buf), "%s", mpd_song_get_tag(song, b->u.i, 0)); mpd_song_free(song); } else - bprintf(buf, sizeof(buf), "%s", ""); + snprintf(buf, sizeof(buf), "%s", ""); if (status) mpd_status_free(status); mpd_response_finish(conn); mpd_connection_free(conn); - return bprintf(b->curstr, BLOCKLEN, b->fmt, buf); + return snprintf(b->curstr, BLOCKLEN, b->fmt, buf); } diff --git a/blocks/volume.c b/blocks/volume.c @@ -44,13 +44,13 @@ getvol(struct Block *b) if (notmuted) { if (abs(vol) < 100) - bprintf(buf, sizeof(buf), "%d%%", (int)vol); + snprintf(buf, sizeof(buf), "%d%%", (int)vol); else /* HACK: digital out is always 100% so just say on */ - bprintf(buf, sizeof(buf), "%s", "on"); + snprintf(buf, sizeof(buf), "%s", "on"); } else - bprintf(buf, sizeof(buf), "%s", "muted"); + snprintf(buf, sizeof(buf), "%s", "muted"); - return bprintf(b->curstr, BLOCKLEN, b->fmt, buf); + return snprintf(b->curstr, BLOCKLEN, b->fmt, buf); } #endif diff --git a/util.c b/util.c @@ -17,19 +17,6 @@ die(const char *errstr, ...) exit(1); } -size_t -bprintf(char *buf, size_t buflen, const char *fmt, ...) -{ - size_t ret; - va_list ap; - - va_start(ap, fmt); - ret = vsnprintf(buf, buflen, fmt, ap); - va_end(ap); - - return (ret < buflen)? ret : buflen; -} - int pscanf(const char *path, const char *fmt, ...) { diff --git a/util.h b/util.h @@ -1,5 +1,4 @@ #define LEN(a) sizeof(a) / sizeof(*a) void die(const char *errstr, ...); -size_t bprintf(char *buf, size_t buflen, const char *fmt, ...); int pscanf(const char *path, const char *fmt, ...);