summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2012-05-05 20:26:54 -0400
committerMike Frysinger <vapier@gentoo.org>2012-05-06 01:17:30 -0400
commit0813a80223e40a5d122dfa86ea41e7b1c986f093 (patch)
tree5db7aa55008ae1cb076c959849d0cd5481d3fed4
parent3969cb2a85d798cd029043566d97aad66dcee8e5 (diff)
downloadopenrc-0813a80223e40a5d122dfa86ea41e7b1c986f093.tar.gz
openrc-0813a80223e40a5d122dfa86ea41e7b1c986f093.tar.bz2
openrc-0813a80223e40a5d122dfa86ea41e7b1c986f093.tar.xz
add a new ARRAY_SIZE macro and use it
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
-rw-r--r--src/includes/helpers.h2
-rw-r--r--src/libeinfo/libeinfo.c6
-rw-r--r--src/rc/start-stop-daemon.c2
3 files changed, 6 insertions, 4 deletions
diff --git a/src/includes/helpers.h b/src/includes/helpers.h
index 39b192a..94e59a8 100644
--- a/src/includes/helpers.h
+++ b/src/includes/helpers.h
@@ -46,6 +46,8 @@
# define _unused
#endif
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
+
/* Some libc implemntations don't have these */
#ifndef TAILQ_CONCAT
#define TAILQ_CONCAT(head1, head2, field) do { \
diff --git a/src/libeinfo/libeinfo.c b/src/libeinfo/libeinfo.c
index eb33193..98cec92 100644
--- a/src/libeinfo/libeinfo.c
+++ b/src/libeinfo/libeinfo.c
@@ -135,7 +135,7 @@ static const struct ecolor ecolors[] = {
{ ECOLOR_BRACKET, BRACKET, "bracket" },
{ ECOLOR_NORMAL, 0, NULL },
};
-static const char *ecolors_str[sizeof(ecolors)/sizeof(ecolors[0])];
+static const char *ecolors_str[ARRAY_SIZE(ecolors)];
static char *flush = NULL;
static char *up = NULL;
@@ -442,7 +442,7 @@ colour_terminal(FILE * EINFO_RESTRICT f)
/* Now setup our colours */
p = ebuffer;
- for (i = 0; i < sizeof(ecolors) / sizeof(ecolors[0]); i++) {
+ for (i = 0; i < ARRAY_SIZE(ecolors); ++i) {
tmp[0] = '\0';
if (ecolors[i].name) {
bold = _md;
@@ -578,7 +578,7 @@ _ecolor(FILE * EINFO_RESTRICT f, ECOLOR color)
if (!colour_terminal(f))
return "";
- for (i = 0; i < sizeof(ecolors) / sizeof(ecolors[0]); i++)
+ for (i = 0; i < ARRAY_SIZE(ecolors); ++i)
if (ecolors[i].color == color)
return ecolors_str[i];
return "";
diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c
index 965b331..d1eb8a5 100644
--- a/src/rc/start-stop-daemon.c
+++ b/src/rc/start-stop-daemon.c
@@ -192,7 +192,7 @@ parse_signal(const char *sig)
else
s = NULL;
- for (i = 0; i < sizeof(signallist) / sizeof(signallist[0]); i++)
+ for (i = 0; i < ARRAY_SIZE(signallist); ++i)
if (strcmp(sig, signallist[i].name) == 0 ||
(s && strcmp(s, signallist[i].name) == 0))
return signallist[i].signal;