Commit: d3d4ceb01a15be1db916fcc4bd7f5b11e9e2fdc1
Parent: 0c398dfa70dc3ff0802ebf8332840a4910a68739
Author: Randy Palamar
Date: Sun, 4 Apr 2021 11:37:12 -0600
replace BLOCKLEN in fn calls with LEN(*)
Diffstat:
5 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/blocks/battery.c b/blocks/battery.c
@@ -43,7 +43,7 @@ batinfo(struct Block *b)
} else
snprintf(buf, sizeof(buf), "%d%% (%s)", perc, state);
- return snprintf(b->curstr, BLOCKLEN, b->fmt, buf);
+ return snprintf(b->curstr, LEN(b->curstr), b->fmt, buf);
}
#elif defined(__OpenBSD__)
@@ -77,6 +77,6 @@ batinfo(struct Block *b)
default:
snprintf(buf, sizeof(buf), "%d%% (unknown)", pi.battery_life);
}
- return snprintf(b->curstr, BLOCKLEN, b->fmt, buf);
+ return snprintf(b->curstr, LEN(b->curstr), b->fmt, buf);
}
#endif
diff --git a/blocks/gettime.c b/blocks/gettime.c
@@ -2,11 +2,12 @@
#include <time.h>
#include "../status.h"
+#include "../util.h"
#include "gettime.h"
size_t
gettime(struct Block *b)
{
time_t t = time(NULL);
- return strftime(b->curstr, BLOCKLEN, b->fmt, localtime(&t)) + 1;
+ return strftime(b->curstr, LEN(b->curstr), b->fmt, localtime(&t));
}
diff --git a/blocks/mpd.c b/blocks/mpd.c
@@ -29,12 +29,12 @@ mpd(struct Block *b)
struct mpd_status *status = NULL;
if (!conn && openconn() != 0)
- return snprintf(b->curstr, BLOCKLEN, b->fmt, "");
+ return snprintf(b->curstr, LEN(b->curstr), b->fmt, "");
if (mpd_connection_get_error(conn)) {
mpd_connection_free(conn);
if (openconn() != 0)
- return snprintf(b->curstr, BLOCKLEN, b->fmt, "");
+ return snprintf(b->curstr, LEN(b->curstr), b->fmt, "");
}
mpd_run_noidle(conn);
@@ -54,5 +54,5 @@ mpd(struct Block *b)
mpd_response_finish(conn);
mpd_send_idle(conn);
- return snprintf(b->curstr, BLOCKLEN, b->fmt, buf);
+ return snprintf(b->curstr, LEN(b->curstr), b->fmt, buf);
}
diff --git a/blocks/volume.c b/blocks/volume.c
@@ -51,6 +51,6 @@ getvol(struct Block *b)
} else
snprintf(buf, sizeof(buf), "%s", "muted");
- return snprintf(b->curstr, BLOCKLEN, b->fmt, buf);
+ return snprintf(b->curstr, LEN(b->curstr), b->fmt, buf);
}
#endif
diff --git a/util.h b/util.h
@@ -1,4 +1,4 @@
-#define LEN(a) sizeof(a) / sizeof(*a)
+#define LEN(a) (sizeof(a) / sizeof(*a))
void die(const char *errstr, ...);
int pscanf(const char *path, const char *fmt, ...);