]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
add and use ARRAY_SIZE
authorJohannes Berg <johannes@sipsolutions.net>
Mon, 8 Dec 2008 11:59:16 +0000 (12:59 +0100)
committerJohannes Berg <johannes@sipsolutions.net>
Mon, 8 Dec 2008 11:59:16 +0000 (12:59 +0100)
iw.h
mesh.c
phy.c

diff --git a/iw.h b/iw.h
index 3967368ef05422e8de7012cfbd122cb43523f094..0ac454939064cfdf66b7adb0236ee2d26fa1f6bf 100644 (file)
--- a/iw.h
+++ b/iw.h
@@ -39,6 +39,8 @@ struct cmd {
                       int argc, char **argv);
 };
 
+#define ARRAY_SIZE(ar) (sizeof(ar)/sizeof(ar[0]))
+
 #define __COMMAND(sect, name, args, nlcmd, flags, hidden, idby, handler)\
        static const struct cmd                                         \
        __cmd_ ## handler ## _ ## nlcmd ## _ ## idby ## _ ## hidden     \
diff --git a/mesh.c b/mesh.c
index 741a662ee49e013155d01938b13337fe6d09a222..d1164226fc851d45fb5fcb6becc93f85c5ba6a5d 100644 (file)
--- a/mesh.c
+++ b/mesh.c
@@ -172,9 +172,7 @@ static void print_all_mesh_param_descr(void)
        int i;
        const char *comma = "";
 
-       for (i = 0;
-            i < sizeof(_mesh_param_descrs)/sizeof(_mesh_param_descrs[0]);
-            ++i) {
+       for (i = 0; i < ARRAY_SIZE(_mesh_param_descrs); i++) {
                printf("%s%s", comma, _mesh_param_descrs[i].name);
                comma = ", ";
        }
@@ -194,12 +192,9 @@ static const struct mesh_param_descr* find_mesh_param(int argc, char **argv,
 
        /* Find out what mesh parameter we want to change. */
        mdescr = NULL;
-       for (i = 0;
-            i < sizeof(_mesh_param_descrs)/sizeof(_mesh_param_descrs[0]);
-            ++i) {
+       for (i = 0; ARRAY_SIZE(_mesh_param_descrs); i++)
                if (!strcmp(_mesh_param_descrs[i].name, argv[0]))
                        return _mesh_param_descrs + i;
-       }
 
        if (!mdescr) {
                printf("Mesh_param must be one of: ");
diff --git a/phy.c b/phy.c
index 45d4e78fefd28b95aed3954bc0df6a60c2ffa62d..74cc1764e81d8863e01acebffd1b56b825e7cb15 100644 (file)
--- a/phy.c
+++ b/phy.c
@@ -45,7 +45,7 @@ static int handle_freqchan(struct nl_msg *msg, bool chan,
                return 1;
 
        if (argc == 2) {
-               for (i = 0; i < sizeof(htmap)/sizeof(htmap[0]); i++) {
+               for (i = 0; i < ARRAY_SIZE(htmap); i++) {
                        if (strcasecmp(htmap[i].name, argv[1]) == 0) {
                                htval = htmap[i].val;
                                break;