diff options
author | Laslo Hunhold <dev@frign.de> | 2017-08-11 13:39:19 +0200 |
---|---|---|
committer | Aaron Marcher <me@drkhsh.at> | 2017-08-11 13:43:11 +0200 |
commit | 1814061396ef5855e2d1815665fc32e0902ccbe9 (patch) | |
tree | bd8f2ffaffe3542a8f85e648210583d844207234 | |
parent | 178c23e3d2b75a99010987bf3e17a82ff7b83b6a (diff) |
Add and use LEN() macro
-rw-r--r-- | slstatus.c | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -28,6 +28,8 @@ #include "arg.h" +#define LEN(x) (sizeof (x) / sizeof *(x)) + struct arg { const char *(*func)(); const char *fmt; @@ -167,13 +169,13 @@ battery_state(const char *bat) if (n != 1) return UNKNOWN_STR; - for (i = 0; i < sizeof(map) / sizeof(*map); i++) { + for (i = 0; i < LEN(map); i++) { if (!strcmp(map[i].state, state)) { break; } } - return (i == sizeof(map) / sizeof(*map)) ? "?" : map[i].symbol; + return (i == LEN(map)) ? "?" : map[i].symbol; } static const char * @@ -745,7 +747,7 @@ vol_perc(const char *card) close(afd); return UNKNOWN_STR; } - for (i = 0; i < (sizeof(vnames) / sizeof((vnames[0]))); i++) { + for (i = 0; i < LEN(vnames); i++) { if (devmask & (1 << i) && !strcmp("vol", vnames[i])) { if (ioctl(afd, MIXER_READ(i), &v) == -1) { warn("vol_perc: ioctl"); @@ -884,8 +886,7 @@ main(int argc, char *argv[]) while (!done) { status_string[0] = '\0'; - for (element = status_string, i = len = 0; - i < sizeof(args) / sizeof(args[0]); + for (element = status_string, i = len = 0; i < LEN(args); ++i, element += len) { argument = args[i]; len = snprintf(element, sizeof(status_string)-1 - len, |