From ce93fa8adbeb31d160cba198e50e3f828e8def50 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Sat, 4 May 2013 17:11:33 +0200 Subject: Use a macro to determine the size of arrays Use following macro instead of "sizeof(x) / sizeof(x[0])" everywhere: #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) Signed-off-by: Lukas Fleischer --- src/config.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/config.c') diff --git a/src/config.c b/src/config.c index 39ac338..da6b049 100644 --- a/src/config.c +++ b/src/config.c @@ -112,7 +112,7 @@ static const struct confvar confmap[] = { struct config_save_status { FILE *fp; - int done[sizeof(confmap) / sizeof(confmap[0])]; + int done[ARRAY_SIZE(confmap)]; }; typedef int (*config_fn_walk_cb_t) (const char *, const char *, void *); @@ -284,7 +284,7 @@ static int config_set_conf(const char *key, const char *value) if (!key) return -1; - for (i = 0; i < sizeof(confmap) / sizeof(confmap[0]); i++) { + for (i = 0; i < ARRAY_SIZE(confmap); i++) { if (!strcmp(confmap[i].key, key)) return confmap[i].fn_parse(confmap[i].target, value); @@ -447,7 +447,7 @@ config_serialize_conf(char *buf, const char *key, if (!key) return -1; - for (i = 0; i < sizeof(confmap) / sizeof(confmap[0]); i++) { + for (i = 0; i < ARRAY_SIZE(confmap); i++) { if (!strcmp(confmap[i].key, key)) { if (confmap[i]. fn_serialize(buf, confmap[i].target)) { @@ -617,7 +617,7 @@ unsigned config_save(void) (void *)&status); /* Set variables that were missing from the configuration file. */ - for (i = 0; i < sizeof(confmap) / sizeof(confmap[0]); i++) { + for (i = 0; i < ARRAY_SIZE(confmap); i++) { if (!status.done[i]) config_save_cb(confmap[i].key, NULL, &status); } -- cgit v1.2.3-54-g00ecf