You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2023/08/17 19:51:57 UTC
[nuttx-apps] 01/03: Change all sizeof(arr)/sizeof(arr[0]) to nitems
This is an automated email from the ASF dual-hosted git repository.
pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit 054cf3b1cb2697fc4f1c114a52c030d5a88a6899
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Wed Aug 16 01:12:50 2023 +0800
Change all sizeof(arr)/sizeof(arr[0]) to nitems
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
builtin/builtin_list.c | 3 ++-
canutils/libcanutils/lib.c | 15 ++++++---------
examples/adxl372_test/adxl372_test_main.c | 9 ++++-----
examples/dac/dac_main.c | 11 ++++-------
examples/ft80x/ft80x_main.c | 8 +++-----
examples/ftpd/ftpd_main.c | 4 ++--
examples/lsm330spi_test/lsm330spi_test_main.c | 9 ++++-----
examples/pdcurses/testcurs_main.c | 3 ++-
examples/usrsocktest/usrsocktest_daemon.c | 17 +++++++----------
examples/usrsocktest/usrsocktest_main.c | 4 ----
examples/usrsocktest/usrsocktest_multi_thread.c | 15 ++++++---------
examples/usrsocktest/usrsocktest_wake_with_signal.c | 4 ----
graphics/lvgl/port/lv_port_keypad.c | 3 ++-
interpreters/bas/bas_statement.c | 3 ++-
netutils/dhcp6c/dhcp6c.c | 7 +++----
netutils/iperf/iperf_main.c | 5 ++---
netutils/ntpclient/ntpclient.c | 7 ++-----
netutils/thttpd/libhttpd.c | 5 +++--
netutils/thttpd/mime_types.h | 5 +++--
netutils/thttpd/tdate_parse.c | 10 ++++------
netutils/webserver/Kconfig | 8 ++++----
netutils/webserver/httpd.c | 3 ++-
system/iptables/iptables.c | 2 +-
system/nxplayer/nxplayer.c | 3 ++-
system/nxplayer/nxplayer_mp3.c | 4 ++--
system/tcpdump/tcpdump.c | 2 +-
system/ubloxmodem/ubloxmodem_main.c | 8 +++-----
system/uorb/test/unit_test.c | 3 ++-
testing/crypto/aescbc.c | 3 ++-
testing/crypto/aesctr.c | 2 +-
testing/crypto/aesxts.c | 4 ++--
testing/crypto/hash.c | 9 +++++----
testing/crypto/hmac.c | 7 ++++---
testing/drivertest/drivertest_framebuffer.c | 3 ++-
testing/drivertest/drivertest_lcd.c | 3 ++-
testing/scanftest/scanftest_main.c | 7 +++----
testing/sensortest/sensortest.c | 4 ++--
wireless/ieee802154/i8sak/i8sak_main.c | 5 ++---
wireless/iwpan/src/iwpan.c | 5 ++---
wireless/wapi/src/wapi.c | 5 ++---
40 files changed, 107 insertions(+), 130 deletions(-)
diff --git a/builtin/builtin_list.c b/builtin/builtin_list.c
index f8fe389b1..dcc10e10b 100644
--- a/builtin/builtin_list.c
+++ b/builtin/builtin_list.c
@@ -25,6 +25,7 @@
#include <nuttx/config.h>
#include <nuttx/lib/builtin.h>
+#include <sys/param.h>
#include <sys/stat.h>
@@ -52,7 +53,7 @@ const struct builtin_s g_builtins[] =
#endif
};
-const int g_builtin_count = sizeof(g_builtins) / sizeof(g_builtins[0]);
+const int g_builtin_count = nitems(g_builtins);
/****************************************************************************
* Private Data
diff --git a/canutils/libcanutils/lib.c b/canutils/libcanutils/lib.c
index f12cfc3f7..f84974a81 100644
--- a/canutils/libcanutils/lib.c
+++ b/canutils/libcanutils/lib.c
@@ -46,6 +46,7 @@
#include <string.h>
#include <stdint.h>
+#include <sys/param.h>
#include <sys/socket.h> /* for sa_family_t */
#include <nuttx/can.h>
#include <netpacket/can.h>
@@ -496,10 +497,6 @@ static const char *protocol_violation_locations[] = {
"unspecified",
};
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
-#endif
-
static int snprintf_error_data(char *buf, size_t len, uint8_t err,
const char **arr, int arr_len)
{
@@ -537,7 +534,7 @@ static int snprintf_error_ctrl(char *buf, size_t len, const struct canfd_frame *
n += snprintf(buf + n, len - n, "{");
n += snprintf_error_data(buf + n, len - n, cf->data[1],
controller_problems,
- ARRAY_SIZE(controller_problems));
+ nitems(controller_problems));
n += snprintf(buf + n, len - n, "}");
return n;
@@ -553,10 +550,10 @@ static int snprintf_error_prot(char *buf, size_t len, const struct canfd_frame *
n += snprintf(buf + n, len - n, "{{");
n += snprintf_error_data(buf + n, len - n, cf->data[2],
protocol_violation_types,
- ARRAY_SIZE(protocol_violation_types));
+ nitems(protocol_violation_types));
n += snprintf(buf + n, len - n, "}{");
if (cf->data[3] > 0 &&
- cf->data[3] < ARRAY_SIZE(protocol_violation_locations))
+ cf->data[3] < nitems(protocol_violation_locations))
n += snprintf(buf + n, len - n, "%s",
protocol_violation_locations[cf->data[3]]);
n += snprintf(buf + n, len - n, "}}");
@@ -575,7 +572,7 @@ void snprintf_can_error_frame(char *buf, size_t len, const struct canfd_frame *c
return;
class = cf->can_id & CAN_EFF_MASK;
- if (class > (1 << ARRAY_SIZE(error_classes))) {
+ if (class > (1 << nitems(error_classes))) {
fprintf(stderr, "Error class %#jx is invalid\n", (uintmax_t)class);
return;
}
@@ -583,7 +580,7 @@ void snprintf_can_error_frame(char *buf, size_t len, const struct canfd_frame *c
if (!sep)
sep = defsep;
- for (i = 0; i < (int)ARRAY_SIZE(error_classes); i++) {
+ for (i = 0; i < (int)nitems(error_classes); i++) {
mask = 1 << i;
if (class & mask) {
if (classes)
diff --git a/examples/adxl372_test/adxl372_test_main.c b/examples/adxl372_test/adxl372_test_main.c
index e30155945..2c05d61ba 100644
--- a/examples/adxl372_test/adxl372_test_main.c
+++ b/examples/adxl372_test/adxl372_test_main.c
@@ -27,7 +27,7 @@
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
-#include <nuttx/fs/fs.h>
+#include <sys/param.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -41,7 +41,6 @@
* Pre-processor Definitions
****************************************************************************/
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
#define PASSED 0
#define SUB_PROMPT "stst >"
@@ -394,7 +393,7 @@ int main(int argc, FAR char *argv[])
adxl372_test, /* ADXL372 accelerometer tests */
};
- FAR char *test_path[ARRAYSIZE(test_ptr_array)];
+ FAR char *test_path[nitems(test_ptr_array)];
if (argc < 1 || *argv[1] == 0 || *(argv[1] + 1) == 0)
{
@@ -490,7 +489,7 @@ int main(int argc, FAR char *argv[])
printf("Set to batch mode.\n");
}
}
- else if (ui >= ARRAYSIZE(test_ptr_array))
+ else if (ui >= nitems(test_ptr_array))
{
printf("Huh?\n");
}
@@ -511,7 +510,7 @@ int main(int argc, FAR char *argv[])
{
printf("ADXL372 sensor diagnostic started in batch mode...\n");
- for (ui = 0; ui < ARRAYSIZE(test_ptr_array); ui++)
+ for (ui = 0; ui < nitems(test_ptr_array); ui++)
{
step_rc = 0;
if (test_ptr_array[ui] != 0)
diff --git a/examples/dac/dac_main.c b/examples/dac/dac_main.c
index c4f335b29..d9dda7010 100644
--- a/examples/dac/dac_main.c
+++ b/examples/dac/dac_main.c
@@ -32,6 +32,7 @@
#include <unistd.h>
#include <sys/ioctl.h>
+#include <sys/param.h>
#include <nuttx/analog/dac.h>
#include <nuttx/arch.h>
@@ -47,10 +48,6 @@
# define CONFIG_EXAMPLES_DAC_DEVPATH "/dev/dac0"
#endif
-#ifndef ARRAY_SIZE
-# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
/****************************************************************************
* Private Types
****************************************************************************/
@@ -226,7 +223,7 @@ static int cmd_dac_put(int argc, FAR const char *argv[])
{
msgs[0].am_channel = g_dacstate.channel;
msgs[0].am_data = data;
- ret = dac_put(g_dacstate.devpath, msgs, ARRAY_SIZE(msgs), delay);
+ ret = dac_put(g_dacstate.devpath, msgs, nitems(msgs), delay);
printf("ret=%d\n", ret);
}
@@ -277,7 +274,7 @@ static void dac_help(void)
"Default: %s Current: %s\n",
CONFIG_EXAMPLES_DAC_DEVPATH,
g_dacstate.devpath ? g_dacstate.devpath : "NONE");
- print_cmds("\nCommands:\n", commands, ARRAY_SIZE(commands), "\n");
+ print_cmds("\nCommands:\n", commands, nitems(commands), "\n");
}
static int arg_string(FAR const char **arg, FAR const char **value)
@@ -422,7 +419,7 @@ int main(int argc, FAR const char *argv[])
}
else
{
- ret = execute_cmd(argc, argv, commands, ARRAY_SIZE(commands));
+ ret = execute_cmd(argc, argv, commands, nitems(commands));
}
return (ret >= 0) ? EXIT_SUCCESS : EXIT_FAILURE;
diff --git a/examples/ft80x/ft80x_main.c b/examples/ft80x/ft80x_main.c
index da79bf92a..c88919747 100644
--- a/examples/ft80x/ft80x_main.c
+++ b/examples/ft80x/ft80x_main.c
@@ -30,6 +30,7 @@
#include <fcntl.h>
#include <errno.h>
+#include <sys/param.h>
#include <nuttx/lcd/ft80x.h>
#include "graphics/ft80x.h"
@@ -88,7 +89,6 @@ static const struct ft80x_exampleinfo_s g_primitives[] =
{ "Alpha Blend", ft80x_prim_alphablend }
};
-#define NPRIMITIVES (sizeof(g_primitives) / sizeof(struct ft80x_exampleinfo_s))
#endif /* CONFIG_EXAMPLES_FT80X_PRIMITIVES */
/* Co-processor display examples. Only a small, but interesting, subset
@@ -139,8 +139,6 @@ static const struct ft80x_exampleinfo_s g_coproc[] =
{ "Logo", ft80x_coproc_logo }
};
-#define NCOPROC (sizeof(g_coproc) / sizeof(struct ft80x_exampleinfo_s))
-
/****************************************************************************
* Private Functions
****************************************************************************/
@@ -308,7 +306,7 @@ int main(int argc, FAR char *argv[])
ft80x_info("FT80x Primitive Functions\n");
- for (i = 0; i < NPRIMITIVES; i++)
+ for (i = 0; i < nitems(g_primitives); i++)
{
ft80x_example(fd, buffer, &g_primitives[i]);
}
@@ -318,7 +316,7 @@ int main(int argc, FAR char *argv[])
ft80x_info("FT80x Co-processor Functions\n");
- for (i = 0; i < NCOPROC; i++)
+ for (i = 0; i < nitems(g_coproc); i++)
{
ft80x_example(fd, buffer, &g_coproc[i]);
}
diff --git a/examples/ftpd/ftpd_main.c b/examples/ftpd/ftpd_main.c
index e0eda11b4..d1052b50c 100644
--- a/examples/ftpd/ftpd_main.c
+++ b/examples/ftpd/ftpd_main.c
@@ -33,6 +33,7 @@
#include <errno.h>
#include <debug.h>
+#include <sys/param.h>
#include <netinet/in.h>
#include <arpa/inet.h>
@@ -65,7 +66,6 @@ static const struct fptd_account_s g_ftpdaccounts[] =
{ FTPD_ACCOUNTFLAG_GUEST, "ftp", NULL, NULL },
{ FTPD_ACCOUNTFLAG_GUEST, "anonymous", NULL, NULL },
};
-#define NACCOUNTS (sizeof(g_ftpdaccounts) / sizeof(struct fptd_account_s))
/****************************************************************************
* Public Data
@@ -139,7 +139,7 @@ static void ftpd_accounts(FTPD_SESSION handle)
int i;
printf("Adding accounts:\n");
- for (i = 0; i < NACCOUNTS; i++)
+ for (i = 0; i < nitems(g_ftpdaccounts); i++)
{
account = &g_ftpdaccounts[i];
diff --git a/examples/lsm330spi_test/lsm330spi_test_main.c b/examples/lsm330spi_test/lsm330spi_test_main.c
index ca1a5361d..f78032a6f 100644
--- a/examples/lsm330spi_test/lsm330spi_test_main.c
+++ b/examples/lsm330spi_test/lsm330spi_test_main.c
@@ -27,7 +27,7 @@
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
-#include <nuttx/fs/fs.h>
+#include <sys/param.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -41,7 +41,6 @@
* Pre-processor Definitions
****************************************************************************/
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
#define PASSED 0
#define SUB_PROMPT "stst >"
@@ -631,7 +630,7 @@ int main(int argc, FAR char *argv[])
lsm330gyro_test, /* LSM330 gyroscope tests */
};
- FAR char *test_path[ARRAYSIZE(test_ptr_array)];
+ FAR char *test_path[nitems(test_ptr_array)];
if (argc < 2 || *argv[1] == 0 || *(argv[1] + 1) == 0)
{
@@ -737,7 +736,7 @@ int main(int argc, FAR char *argv[])
printf("Set to batch mode.\n");
}
}
- else if (ui >= ARRAYSIZE(test_ptr_array))
+ else if (ui >= nitems(test_ptr_array))
{
printf("Huh?\n");
}
@@ -757,7 +756,7 @@ int main(int argc, FAR char *argv[])
else /* not interactive mode */
{
printf("LSM330 sensor diagnostic started in batch mode...\n");
- for (ui = 0; ui < ARRAYSIZE(test_ptr_array); ui++)
+ for (ui = 0; ui < nitems(test_ptr_array); ui++)
{
step_rc = 0;
if (test_ptr_array[ui] != 0)
diff --git a/examples/pdcurses/testcurs_main.c b/examples/pdcurses/testcurs_main.c
index 14ac2ed88..14d2951d2 100644
--- a/examples/pdcurses/testcurs_main.c
+++ b/examples/pdcurses/testcurs_main.c
@@ -29,6 +29,7 @@
#include <stdio.h>
#include <ctype.h>
#include <string.h>
+#include <sys/param.h>
#include "graphics/curses.h"
@@ -123,7 +124,7 @@ static const COMMAND command[] =
#endif
};
-#define MAX_OPTIONS (sizeof(command) / sizeof(COMMAND))
+#define MAX_OPTIONS nitems(command)
static int height;
static int width;
diff --git a/examples/usrsocktest/usrsocktest_daemon.c b/examples/usrsocktest/usrsocktest_daemon.c
index e2b15888b..37303fec1 100644
--- a/examples/usrsocktest/usrsocktest_daemon.c
+++ b/examples/usrsocktest/usrsocktest_daemon.c
@@ -36,6 +36,7 @@
#include <pthread.h>
#include <unistd.h>
+#include <sys/param.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
@@ -58,10 +59,6 @@
#define TEST_SOCKET_SOCKID_BASE 10000U
#define TEST_SOCKET_COUNT 8
-#ifndef ARRAY_SIZE
-# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
#define noinline
/****************************************************************************
@@ -140,7 +137,7 @@ static int test_socket_alloc(FAR struct daemon_priv_s *priv)
{
int i;
- for (i = 0; i < ARRAY_SIZE(priv->test_sockets); i++)
+ for (i = 0; i < nitems(priv->test_sockets); i++)
{
FAR struct test_socket_s *tsock = &priv->test_sockets[i];
@@ -172,7 +169,7 @@ static FAR struct test_socket_s *test_socket_get(
}
sockid -= TEST_SOCKET_SOCKID_BASE;
- if (sockid >= ARRAY_SIZE(priv->test_sockets))
+ if (sockid >= nitems(priv->test_sockets))
{
return NULL;
}
@@ -245,13 +242,13 @@ static int tsock_send_event(int fd, FAR struct daemon_priv_s *priv,
event.head.flags = USRSOCK_MESSAGE_FLAG_EVENT;
event.head.msgid = USRSOCK_MESSAGE_SOCKET_EVENT;
- for (i = 0; i < ARRAY_SIZE(priv->test_sockets); i++)
+ for (i = 0; i < nitems(priv->test_sockets); i++)
{
if (tsock == &priv->test_sockets[i])
break;
}
- if (i == ARRAY_SIZE(priv->test_sockets))
+ if (i == nitems(priv->test_sockets))
{
return -EINVAL;
}
@@ -1777,7 +1774,7 @@ static int for_each_connection(int fd, FAR struct daemon_priv_s *priv,
{
int i;
- for (i = 0; i < ARRAY_SIZE(priv->test_sockets); i++)
+ for (i = 0; i < nitems(priv->test_sockets); i++)
{
FAR struct test_socket_s *tsock = &priv->test_sockets[i];
@@ -2114,7 +2111,7 @@ int usrsocktest_daemon_stop(void)
goto out;
}
- for (i = 0; i < ARRAY_SIZE(priv->test_sockets); i++)
+ for (i = 0; i < nitems(priv->test_sockets); i++)
{
if (priv->test_sockets[i].opened && priv->test_sockets[i].endp != NULL)
{
diff --git a/examples/usrsocktest/usrsocktest_main.c b/examples/usrsocktest/usrsocktest_main.c
index 2d854d87a..9545eac07 100644
--- a/examples/usrsocktest/usrsocktest_main.c
+++ b/examples/usrsocktest/usrsocktest_main.c
@@ -54,10 +54,6 @@
#define usrsocktest_dbg(...) ((void)0)
-#ifndef ARRAY_SIZE
-# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
/****************************************************************************
* Private Data
****************************************************************************/
diff --git a/examples/usrsocktest/usrsocktest_multi_thread.c b/examples/usrsocktest/usrsocktest_multi_thread.c
index e9f56fbd3..a233f3e34 100644
--- a/examples/usrsocktest/usrsocktest_multi_thread.c
+++ b/examples/usrsocktest/usrsocktest_multi_thread.c
@@ -22,6 +22,7 @@
* Included Files
****************************************************************************/
+#include <sys/param.h>
#include <sys/socket.h>
#include <assert.h>
#include <netinet/in.h>
@@ -34,10 +35,6 @@
* Pre-processor Definitions
****************************************************************************/
-#ifndef ARRAY_SIZE
-# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
/****************************************************************************
* Private Types
****************************************************************************/
@@ -115,12 +112,12 @@ TEST_SETUP(multithread)
{
int i;
- for (i = 0; i < ARRAY_SIZE(sds); i++)
+ for (i = 0; i < nitems(sds); i++)
{
sds[i] = -1;
}
- for (i = 0; i < ARRAY_SIZE(tids); i++)
+ for (i = 0; i < nitems(tids); i++)
{
tids[i] = -1;
}
@@ -150,7 +147,7 @@ TEST_TEAR_DOWN(multithread)
int ret;
int i;
- for (i = 0; i < ARRAY_SIZE(tids); i++)
+ for (i = 0; i < nitems(tids); i++)
{
if (tids[i] != -1)
{
@@ -161,7 +158,7 @@ TEST_TEAR_DOWN(multithread)
}
}
- for (i = 0; i < ARRAY_SIZE(sds); i++)
+ for (i = 0; i < nitems(sds); i++)
{
if (sds[i] != -1)
{
@@ -213,7 +210,7 @@ TEST(multithread, open_close)
/* Launch worker threads. */
- for (i = 0; i < ARRAY_SIZE(tids); i++)
+ for (i = 0; i < nitems(tids); i++)
{
ret = pthread_create(&tids[i], NULL, usrsock_socket_multitask_thread,
sds + i);
diff --git a/examples/usrsocktest/usrsocktest_wake_with_signal.c b/examples/usrsocktest/usrsocktest_wake_with_signal.c
index 8cf0af443..ceb84fca5 100644
--- a/examples/usrsocktest/usrsocktest_wake_with_signal.c
+++ b/examples/usrsocktest/usrsocktest_wake_with_signal.c
@@ -38,10 +38,6 @@
* Pre-processor Definitions
****************************************************************************/
-#ifndef ARRAY_SIZE
-# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
#define TEST_FLAG_PAUSE_USRSOCK_HANDLING (1 << 0)
#define TEST_FLAG_DAEMON_ABORT (1 << 1)
#define TEST_FLAG_MULTI_THREAD (1 << 2)
diff --git a/graphics/lvgl/port/lv_port_keypad.c b/graphics/lvgl/port/lv_port_keypad.c
index f45099ca5..e80f6d774 100644
--- a/graphics/lvgl/port/lv_port_keypad.c
+++ b/graphics/lvgl/port/lv_port_keypad.c
@@ -24,6 +24,7 @@
#include <sys/types.h>
#include <sys/ioctl.h>
+#include <sys/param.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -114,7 +115,7 @@ static uint32_t keypad_get_key(int fd)
return 0;
}
- for (i = 0; i < sizeof(g_keypad_map) / sizeof(struct keypad_map_s); i++)
+ for (i = 0; i < nitems(g_keypad_map); i++)
{
int bit = g_keypad_map[i].bit;
diff --git a/interpreters/bas/bas_statement.c b/interpreters/bas/bas_statement.c
index 194123677..482f94f62 100644
--- a/interpreters/bas/bas_statement.c
+++ b/interpreters/bas/bas_statement.c
@@ -32,6 +32,7 @@
#include <stdlib.h>
#include <strings.h>
#include <assert.h>
+#include <sys/param.h>
#include "bas_statement.h"
@@ -1181,7 +1182,7 @@ struct Value *stmt_EDIT(struct Value *value)
String_new(&cmd);
String_appendChars(&cmd, visual);
String_appendChar(&cmd, ' ');
- for (i = 0; i < sizeof(gotoLine) / sizeof(gotoLine[0]); ++i)
+ for (i = 0; i < nitems(gotoLine); ++i)
{
if (strcmp(basename, gotoLine[i].editor) == 0)
{
diff --git a/netutils/dhcp6c/dhcp6c.c b/netutils/dhcp6c/dhcp6c.c
index 8fc9f8210..678ce4db5 100644
--- a/netutils/dhcp6c/dhcp6c.c
+++ b/netutils/dhcp6c/dhcp6c.c
@@ -24,6 +24,7 @@
#include <nuttx/config.h>
#include <nuttx/compiler.h>
+#include <nuttx/clock.h>
#include <time.h>
#include <fcntl.h>
@@ -40,7 +41,7 @@
#include <malloc.h>
#include <pthread.h>
#include <sys/time.h>
-#include <nuttx/clock.h>
+#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <netinet/in.h>
@@ -63,8 +64,6 @@
#define DHCPV6_DUID_LLADDR 3
#define DHCPV6_REQ_DELAY 1
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
-
#define dhcpv6_for_each_option(_o, start, end, otype, olen, odata)\
for ((_o) = (FAR uint8_t *)(start); (_o) + 4 <= (FAR uint8_t *)(end) &&\
((otype) = (_o)[0] << 8 | (_o)[1]) && ((odata) = (FAR void *)&(_o)[4]) &&\
@@ -614,7 +613,7 @@ static void dhcp6c_send(FAR void *handle, enum dhcpv6_msg_e type,
dhcp6c_set_iov(&iov[9], &hdr_ia_pd, sizeof(hdr_ia_pd));
dhcp6c_set_iov(&iov[10], ia_pd, ia_pd_len);
- cnt = ARRAY_SIZE(iov);
+ cnt = nitems(iov);
if (type == DHCPV6_MSG_INFO_REQ)
{
cnt = 5;
diff --git a/netutils/iperf/iperf_main.c b/netutils/iperf/iperf_main.c
index a51359091..46abf8bbb 100644
--- a/netutils/iperf/iperf_main.c
+++ b/netutils/iperf/iperf_main.c
@@ -85,7 +85,7 @@ static void iperf_showusage(FAR const char *progname,
printf("iperf command:\n");
arg_print_glossary(stdout, (FAR void **)args, NULL);
- arg_freetable((FAR void **)args, sizeof(*args) / sizeof(FAR void *));
+ arg_freetable((FAR void **)args, 1);
exit(exitcode);
}
@@ -301,8 +301,7 @@ int main(int argc, FAR char *argv[])
iperf_start(&cfg);
out:
- arg_freetable((FAR void **)&iperf_args,
- sizeof(iperf_args) / sizeof(FAR void *));
+ arg_freetable((FAR void **)&iperf_args, 1);
return 0;
}
diff --git a/netutils/ntpclient/ntpclient.c b/netutils/ntpclient/ntpclient.c
index 7374c00a2..8ec85d22e 100644
--- a/netutils/ntpclient/ntpclient.c
+++ b/netutils/ntpclient/ntpclient.c
@@ -27,6 +27,7 @@
#include <stdbool.h>
#include <stdint.h>
+#include <sys/param.h>
#include <sys/socket.h>
#include <sys/time.h>
@@ -100,10 +101,6 @@
#define MAX_SERVER_SELECTION_RETRIES 3
-#ifndef ARRAY_SIZE
-# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
#ifndef STR
# define STR2(x) #x
# define STR(x) STR2(x)
@@ -1003,7 +1000,7 @@ static int ntp_get_next_hostip(FAR struct ntp_servers_s *srvs,
/* Refresh DNS for new IP-addresses. */
ret = ntp_gethostip_multi(hostname, srvs->list,
- ARRAY_SIZE(srvs->list));
+ nitems(srvs->list));
if (ret <= 0)
{
return ERROR;
diff --git a/netutils/thttpd/libhttpd.c b/netutils/thttpd/libhttpd.c
index bdc747caf..9c07f93e7 100644
--- a/netutils/thttpd/libhttpd.c
+++ b/netutils/thttpd/libhttpd.c
@@ -43,6 +43,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
+#include <sys/param.h>
#include <stdint.h>
#include <stdbool.h>
@@ -1503,7 +1504,7 @@ static void figure_mime(httpd_conn *hc)
if (ext_len == enc_tab[i].ext_len &&
strncasecmp(ext, enc_tab[i].ext, ext_len) == 0)
{
- if (n_me_indexes < sizeof(me_indexes) / sizeof(*me_indexes))
+ if (n_me_indexes < nitems(me_indexes))
{
me_indexes[n_me_indexes] = i;
++n_me_indexes;
@@ -3284,7 +3285,7 @@ int httpd_start_request(httpd_conn *hc, struct timeval *nowp)
/* Check for an index file. */
- for (i = 0; i < sizeof(index_names) / sizeof(char *); ++i)
+ for (i = 0; i < nitems(index_names); ++i)
{
httpd_realloc_str(&indexname, &maxindexname,
expnlen + 1 + strlen(index_names[i]));
diff --git a/netutils/thttpd/mime_types.h b/netutils/thttpd/mime_types.h
index 5c14a74b8..6b6b29005 100644
--- a/netutils/thttpd/mime_types.h
+++ b/netutils/thttpd/mime_types.h
@@ -45,6 +45,7 @@
****************************************************************************/
#include <sys/types.h>
+#include <sys/param.h>
/****************************************************************************
* Private Types
@@ -73,7 +74,7 @@ static struct mime_entry enc_tab[] =
{ "gz", 0, "gzip", 0 },
{ "uu", 0, "x-uuencode", 0 },
};
-static const int n_enc_tab = sizeof(enc_tab) / sizeof(*enc_tab);
+static const int n_enc_tab = nitems(enc_tab);
/* A list of file extensions followed by the corresponding MIME type.
* Extensions not found in the table are returned as text/plain.
@@ -273,6 +274,6 @@ static struct mime_entry typ_tab[] =
{ "xyz", 0, "chemical/x-xyz", 0 },
{ "zip", 0, "application/zip", 0 },
};
-static const int n_typ_tab = sizeof(typ_tab) / sizeof(*typ_tab);
+static const int n_typ_tab = nitems(typ_tab);
#endif /* __APPS_NETUTILS_THTTPD_MIME_TYPES_H */
diff --git a/netutils/thttpd/tdate_parse.c b/netutils/thttpd/tdate_parse.c
index de3f8851d..995af3a95 100644
--- a/netutils/thttpd/tdate_parse.c
+++ b/netutils/thttpd/tdate_parse.c
@@ -143,14 +143,13 @@ static int scan_wday(char *str_wday, long *tm_wdayP)
if (!sorted)
{
- qsort(wday_tab, sizeof(wday_tab) / sizeof(struct strlong),
+ qsort(wday_tab, nitems(wday_tab),
sizeof(struct strlong), strlong_compare);
sorted = 1;
}
pound_case(str_wday);
- return strlong_search(str_wday, wday_tab,
- sizeof(wday_tab) / sizeof(struct strlong), tm_wdayP);
+ return strlong_search(str_wday, wday_tab, nitems(wday_tab), tm_wdayP);
}
#endif /* Day of week not yet supported by NuttX */
@@ -176,14 +175,13 @@ static int scan_mon(char *str_mon, long *tm_monP)
if (!sorted)
{
- qsort(mon_tab, sizeof(mon_tab) / sizeof(struct strlong),
+ qsort(mon_tab, nitems(mon_tab),
sizeof(struct strlong), strlong_compare);
sorted = 1;
}
pound_case(str_mon);
- return strlong_search(str_mon, mon_tab,
- sizeof(mon_tab) / sizeof(struct strlong), tm_monP);
+ return strlong_search(str_mon, mon_tab, nitems(mon_tab), tm_monP);
}
#endif
diff --git a/netutils/webserver/Kconfig b/netutils/webserver/Kconfig
index 1140f0c56..6f33542e6 100644
--- a/netutils/webserver/Kconfig
+++ b/netutils/webserver/Kconfig
@@ -57,12 +57,12 @@ config NETUTILS_HTTPD_CGIPATH
used thus:
const static struct httpd_cgi_call a[] = {
- { NULL, "/abc", cgi_abc },
- { NULL, "/xyz", cgi_xyz }
+ { NULL, "/abc", cgi_abc },
+ { NULL, "/xyz", cgi_xyz }
};
- for (i = 0; i < sizeof a / sizeof *a; i++) {
- httpd_cgi_register(&a[i]);
+ for (i = 0; i < nitems(a); i++) {
+ httpd_cgi_register(&a[i]);
}
Where (under NETUTILS_HTTPD_CGIPATH) the "/xyz" is a URL path,
diff --git a/netutils/webserver/httpd.c b/netutils/webserver/httpd.c
index 14aa2a33f..4602e65e9 100644
--- a/netutils/webserver/httpd.c
+++ b/netutils/webserver/httpd.c
@@ -50,6 +50,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
+#include <sys/param.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -988,7 +989,7 @@ int httpd_send_headers(struct httpd_state *pstate, int status, int len)
{
mime = "text/plain";
- for (i = 0; i < sizeof a / sizeof *a; i++)
+ for (i = 0; i < nitems(a); i++)
{
if (strncmp(a[i].ext, ptr + 1, strlen(a[i].ext)) == 0)
{
diff --git a/system/iptables/iptables.c b/system/iptables/iptables.c
index 8cbc958ac..3021619bb 100644
--- a/system/iptables/iptables.c
+++ b/system/iptables/iptables.c
@@ -455,6 +455,6 @@ int main(int argc, FAR char *argv[])
printf("Unknown table: %s\n", args.table->sval[0]);
}
- arg_freetable((FAR void **)&args, sizeof(args) / sizeof(FAR void *));
+ arg_freetable((FAR void **)&args, 1);
return ret;
}
diff --git a/system/nxplayer/nxplayer.c b/system/nxplayer/nxplayer.c
index 626000982..a0d10e590 100644
--- a/system/nxplayer/nxplayer.c
+++ b/system/nxplayer/nxplayer.c
@@ -38,6 +38,7 @@
#include <strings.h>
#include <sys/ioctl.h>
#include <sys/types.h>
+#include <sys/param.h>
#include <unistd.h>
#ifdef CONFIG_NXPLAYER_HTTP_STREAMING_SUPPORT
# include <sys/time.h>
@@ -1900,7 +1901,7 @@ static int nxplayer_playinternal(FAR struct nxplayer_s *pplayer,
goto err_out_nodev;
}
- for (c = 0; c < sizeof(g_dec_ops) / sizeof(g_dec_ops[0]); c++)
+ for (c = 0; c < nitems(g_dec_ops); c++)
{
if (g_dec_ops[c].format == filefmt)
{
diff --git a/system/nxplayer/nxplayer_mp3.c b/system/nxplayer/nxplayer_mp3.c
index 7f62241a5..445fe29dd 100644
--- a/system/nxplayer/nxplayer_mp3.c
+++ b/system/nxplayer/nxplayer_mp3.c
@@ -29,6 +29,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
+#include <sys/param.h>
#include <unistd.h>
#include <nuttx/audio/audio.h>
@@ -157,8 +158,7 @@ static int nxplayer_parse_mpeg(uint32_t header, FAR uint32_t *samplerate,
padding = (header >> 9) & 1;
mode = (header >> 6) & 3;
- if (sr_idx >= sizeof(g_mpa_freq_tab) / sizeof(g_mpa_freq_tab[0]) ||
- br_idx >= 0xf)
+ if (sr_idx >= nitems(g_mpa_freq_tab) || br_idx >= 0xf)
{
return -EINVAL;
}
diff --git a/system/tcpdump/tcpdump.c b/system/tcpdump/tcpdump.c
index 2a43cfc36..c1988d401 100644
--- a/system/tcpdump/tcpdump.c
+++ b/system/tcpdump/tcpdump.c
@@ -312,6 +312,6 @@ int main(int argc, FAR char *argv[])
close(cfgs.fd);
out:
- arg_freetable((FAR void **)&args, sizeof(args) / sizeof(FAR void *));
+ arg_freetable((FAR void **)&args, 1);
return 0;
}
diff --git a/system/ubloxmodem/ubloxmodem_main.c b/system/ubloxmodem/ubloxmodem_main.c
index 2f49f9254..76f827f62 100644
--- a/system/ubloxmodem/ubloxmodem_main.c
+++ b/system/ubloxmodem/ubloxmodem_main.c
@@ -42,6 +42,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
+#include <sys/param.h>
#include <debug.h>
#include <errno.h>
@@ -247,9 +248,7 @@ static int ubloxmodem_help(FAR struct ubloxmodem_cxt *cxt)
printf("Usage: ubloxmodem <cmd> [arguments]\n"
" where <cmd> is one of\n");
- for (i = 0;
- i < sizeof(cmdmap) / sizeof(struct cmdinfo);
- i++)
+ for (i = 0; i < nitems(cmdmap); i++)
{
printf("%s\n %s\n %s\n",
cmdmap[i].name,
@@ -375,8 +374,7 @@ static int ubloxmodem_parse(FAR struct ubloxmodem_cxt *cxt)
{
int i;
- for (i = 0;
- i < sizeof(cmdmap) / sizeof(struct cmdinfo) &&
+ for (i = 0; i < nitems(cmdmap) &&
cxt->cmd == UBLOXMODEM_CMD_UNKNOWN;
i++)
{
diff --git a/system/uorb/test/unit_test.c b/system/uorb/test/unit_test.c
index 902acde3d..471b471c3 100644
--- a/system/uorb/test/unit_test.c
+++ b/system/uorb/test/unit_test.c
@@ -30,6 +30,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <sys/param.h>
#include "utility.h"
@@ -89,7 +90,7 @@ static int pubsubtest_thread_entry(int argc, FAR char *argv[])
/* wait for up to 500ms for data */
- pret = poll(&fds[0], (sizeof(fds) / sizeof(fds[0])), 500);
+ pret = poll(&fds[0], nitems(fds), 500);
if (fds[0].revents & POLLIN)
{
unsigned elt;
diff --git a/testing/crypto/aescbc.c b/testing/crypto/aescbc.c
index e21d23548..638f4f411 100644
--- a/testing/crypto/aescbc.c
+++ b/testing/crypto/aescbc.c
@@ -27,6 +27,7 @@
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
+#include <sys/param.h>
#include <crypto/cryptodev.h>
#include <crypto/md5.h>
#include <crypto/sha1.h>
@@ -192,7 +193,7 @@ int main(int argc, char *argv[])
int ret;
unsigned char out[64];
- for (int i = 0; i < sizeof(testcase) / sizeof(struct tb); i++)
+ for (int i = 0; i < nitems(testcase); i++)
{
ret = syscrypt(testcase[i].key, 16, testcase[i].iv, testcase[i].plain,
out, testcase[i].len, 1);
diff --git a/testing/crypto/aesctr.c b/testing/crypto/aesctr.c
index ee6e13c97..852b179eb 100644
--- a/testing/crypto/aesctr.c
+++ b/testing/crypto/aesctr.c
@@ -351,7 +351,7 @@ int main(int argc, FAR char **argv)
int fail = 0;
int i;
- for (i = 0; i < (sizeof(tests) / sizeof(tests[0])); i++)
+ for (i = 0; i < nitems(tests); i++)
{
fail += run(i);
}
diff --git a/testing/crypto/aesxts.c b/testing/crypto/aesxts.c
index b99698db3..dce7a9166 100644
--- a/testing/crypto/aesxts.c
+++ b/testing/crypto/aesxts.c
@@ -32,6 +32,7 @@
#include <sys/types.h>
#include <sys/ioctl.h>
+#include <sys/param.h>
#include <crypto/rijndael.h>
#include <crypto/cryptodev.h>
#include <err.h>
@@ -1727,7 +1728,6 @@ struct aes_xts_tv aes_xts_test_vectors[] =
},
},
};
-#define N_VECTORS (sizeof(aes_xts_test_vectors) / sizeof(*aes_xts_test_vectors))
static int match(FAR unsigned char *a, FAR unsigned char *b, size_t len)
{
@@ -1837,7 +1837,7 @@ int main(int argc, FAR char **argv)
int fail = 0;
size_t i;
- for (i = 0; i < N_VECTORS; i++)
+ for (i = 0; i < nitems(aes_xts_test_vectors); i++)
{
tv = &aes_xts_test_vectors[i];
diff --git a/testing/crypto/hash.c b/testing/crypto/hash.c
index 175853fe9..5490c92aa 100644
--- a/testing/crypto/hash.c
+++ b/testing/crypto/hash.c
@@ -25,6 +25,7 @@
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
+#include <sys/param.h>
#include <crypto/cryptodev.h>
#include <crypto/md5.h>
#include <crypto/sha1.h>
@@ -329,7 +330,7 @@ int main(void)
printf("syshash init failed\n");
}
- for (i = 0; i < sizeof(md5_testcase) / sizeof(tb); i++)
+ for (i = 0; i < nitems(md5_testcase); i++)
{
ret = syshash_start(&md5_ctx, CRYPTO_MD5);
if (ret != 0)
@@ -365,7 +366,7 @@ int main(void)
}
}
- for (i = 0; i < sizeof(sha_testcase) / sizeof(struct tb); i++)
+ for (i = 0; i < nitems(sha_testcase); i++)
{
ret = syshash_start(&sha1_ctx, CRYPTO_SHA1);
if (ret != 0)
@@ -420,7 +421,7 @@ int main(void)
}
}
- for (i = 0; i < sizeof(sha_testcase) / sizeof(struct tb); i++)
+ for (i = 0; i < nitems(sha_testcase); i++)
{
ret = syshash_start(&sha2_256_ctx, CRYPTO_SHA2_256);
if (ret != 0)
@@ -473,7 +474,7 @@ int main(void)
}
}
- for (i = 0; i < sizeof(sha512_testcase) / sizeof(struct tb); i++)
+ for (i = 0; i < nitems(sha512_testcase); i++)
{
ret = syshash_start(&sha2_512_ctx, CRYPTO_SHA2_512);
if (ret != 0)
diff --git a/testing/crypto/hmac.c b/testing/crypto/hmac.c
index fda24dd27..cbad8decb 100644
--- a/testing/crypto/hmac.c
+++ b/testing/crypto/hmac.c
@@ -25,6 +25,7 @@
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
+#include <sys/param.h>
#include <crypto/cryptodev.h>
#include <crypto/md5.h>
#include <crypto/sha1.h>
@@ -192,7 +193,7 @@ int main(void)
{
char output[32];
int ret = 0;
- for (int i = 0; i < sizeof(testcase) / sizeof(struct tb); i++)
+ for (int i = 0; i < nitems(testcase) i++)
{
ret += syshmac(CRYPTO_MD5_HMAC, testcase[i].key,
testcase[i].keylen,
@@ -215,7 +216,7 @@ int main(void)
}
}
- for (int i = 0; i < sizeof(testcase) / sizeof(struct tb); i++)
+ for (int i = 0; i < nitems(testcase); i++)
{
ret = syshmac(CRYPTO_SHA1_HMAC, testcase[i].key,
testcase[i].keylen,
@@ -238,7 +239,7 @@ int main(void)
}
}
- for (int i = 0; i < sizeof(testcase) / sizeof(struct tb); i++)
+ for (int i = 0; i < nitems(testcase); i++)
{
ret = syshmac(CRYPTO_SHA2_256_HMAC, testcase[i].key,
testcase[i].keylen,
diff --git a/testing/drivertest/drivertest_framebuffer.c b/testing/drivertest/drivertest_framebuffer.c
index 5302c5919..a0566cea8 100644
--- a/testing/drivertest/drivertest_framebuffer.c
+++ b/testing/drivertest/drivertest_framebuffer.c
@@ -30,6 +30,7 @@
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <sys/param.h>
#include <stdio.h>
#include <stdlib.h>
@@ -283,7 +284,7 @@ static void test_case_fb_2(FAR void **state)
const uint32_t xres = fb_state->fb_info.video_info.xres;
const uint32_t yres = fb_state->fb_info.video_info.yres;
- step_num = sizeof(colors_to_show) / sizeof(uint32_t);
+ step_num = nitems(colors_to_show);
step_width = xres / step_num;
for (i = 0; i < step_num; i++)
{
diff --git a/testing/drivertest/drivertest_lcd.c b/testing/drivertest/drivertest_lcd.c
index 2e0a2f687..e9ca3713f 100644
--- a/testing/drivertest/drivertest_lcd.c
+++ b/testing/drivertest/drivertest_lcd.c
@@ -32,6 +32,7 @@
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <sys/param.h>
#include <stdio.h>
#include <stdlib.h>
@@ -342,7 +343,7 @@ static void test_case_lcd_2(FAR void **state)
const uint32_t xres = lcd_state->lcd_info.video_info.xres;
const uint32_t yres = lcd_state->lcd_info.video_info.yres;
- step_num = sizeof(colors_to_show) / sizeof(uint32_t);
+ step_num = nitems(colors_to_show);
step_width = xres / step_num;
for (i = 0; i < step_num; i++)
{
diff --git a/testing/scanftest/scanftest_main.c b/testing/scanftest/scanftest_main.c
index df1d7791b..b51bea89d 100644
--- a/testing/scanftest/scanftest_main.c
+++ b/testing/scanftest/scanftest_main.c
@@ -61,6 +61,7 @@
#include <nuttx/config.h>
#include <sys/types.h>
+#include <sys/param.h>
#include <stdint.h>
#include <stdbool.h>
@@ -78,8 +79,6 @@
* Pre-processor Definitions
****************************************************************************/
-#define ARRAYSIZE(a) (sizeof (a) / sizeof (a)[0])
-
/****************************************************************************
* Private Types
****************************************************************************/
@@ -1152,7 +1151,7 @@ int main(int argc, FAR char *argv[])
"assignments...\n",
i ? 'f' : 's');
- for (t = 0; t < ARRAYSIZE(test_data); ++t)
+ for (t = 0; t < nitems(test_data); ++t)
{
/* Prefill the arguments with zeroes. */
@@ -1329,7 +1328,7 @@ int main(int argc, FAR char *argv[])
/* Test the char, short, and long specification-modifiers. */
printf("\nTesting scanf()'s type-modifiers...\n");
- for (t = 0; t < ARRAYSIZE(type_data); ++t)
+ for (t = 0; t < nitems(type_data); ++t)
{
unsigned char hhu;
unsigned short hu;
diff --git a/testing/sensortest/sensortest.c b/testing/sensortest/sensortest.c
index 847db9523..76c004b68 100644
--- a/testing/sensortest/sensortest.c
+++ b/testing/sensortest/sensortest.c
@@ -31,6 +31,7 @@
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
+#include <sys/param.h>
#include <unistd.h>
#include <nuttx/sensors/sensor.h>
@@ -39,7 +40,6 @@
* Pre-processor Definitions
****************************************************************************/
-#define ARRAYSIZE(a) (sizeof(a) / sizeof(a)[0])
#define DEVNAME_FMT "/dev/uorb/sensor_%s"
#define DEVNAME_MAX 64
@@ -317,7 +317,7 @@ int main(int argc, FAR char *argv[])
if (optind < argc)
{
name = argv[optind];
- for (idx = 0; idx < ARRAYSIZE(g_sensor_info); idx++)
+ for (idx = 0; idx < nitems(g_sensor_info); idx++)
{
if (!strncmp(name, g_sensor_info[idx].name,
strlen(g_sensor_info[idx].name)))
diff --git a/wireless/ieee802154/i8sak/i8sak_main.c b/wireless/ieee802154/i8sak/i8sak_main.c
index f7ad5ebea..f052dc0e0 100644
--- a/wireless/ieee802154/i8sak/i8sak_main.c
+++ b/wireless/ieee802154/i8sak/i8sak_main.c
@@ -44,6 +44,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
+#include <sys/param.h>
#include <arpa/inet.h>
#include <nuttx/queue.h>
@@ -102,8 +103,6 @@ static const struct i8sak_command_s g_i8sak_commands[] =
{"tx", (CODE void *)i8sak_tx_cmd},
};
-#define NCOMMANDS (sizeof(g_i8sak_commands) / sizeof(struct i8sak_command_s))
-
static sq_queue_t g_i8sak_free;
static sq_queue_t g_i8sak_instances;
static struct i8sak_s g_i8sak_pool[CONFIG_IEEE802154_I8SAK_NINSTANCES];
@@ -893,7 +892,7 @@ int main(int argc, FAR char *argv[])
/* Find the command in the g_i8sak_command[] list */
i8sakcmd = NULL;
- for (i = 0; i < NCOMMANDS; i++)
+ for (i = 0; i < nitems(g_i8sak_commands); i++)
{
FAR const struct i8sak_command_s *cmd = &g_i8sak_commands[i];
if (strcmp(argv[argind], cmd->name) == 0)
diff --git a/wireless/iwpan/src/iwpan.c b/wireless/iwpan/src/iwpan.c
index 4c32ee3bf..d4114a03b 100644
--- a/wireless/iwpan/src/iwpan.c
+++ b/wireless/iwpan/src/iwpan.c
@@ -22,6 +22,7 @@
* Included Files
****************************************************************************/
+#include <sys/param.h>
#include <sys/socket.h>
#include <stdio.h>
#include <stdlib.h>
@@ -94,8 +95,6 @@ static const struct iwpan_command_s g_iwpan_commands[] =
{"txpwr", 2, (CODE void *)iwpan_txpwr_cmd},
};
-#define NCOMMANDS (sizeof(g_iwpan_commands) / sizeof(struct iwpan_command_s))
-
/****************************************************************************
* Private Functions
****************************************************************************/
@@ -660,7 +659,7 @@ int main(int argc, FAR char *argv[])
/* Find the command in the g_iwpan_command[] list */
iwpancmd = NULL;
- for (i = 0; i < NCOMMANDS; i++)
+ for (i = 0; i < nitems(g_iwpan_commands); i++)
{
FAR const struct iwpan_command_s *cmd = &g_iwpan_commands[i];
if (strcmp(cmdname, cmd->name) == 0)
diff --git a/wireless/wapi/src/wapi.c b/wireless/wapi/src/wapi.c
index 15c5eb89b..f5b35142c 100644
--- a/wireless/wapi/src/wapi.c
+++ b/wireless/wapi/src/wapi.c
@@ -44,6 +44,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <strings.h>
+#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
@@ -137,8 +138,6 @@ static const struct wapi_command_s g_wapi_commands[] =
* Pre-processor Definitions
****************************************************************************/
-#define NCOMMANDS (sizeof(g_wapi_commands) / sizeof(struct wapi_command_s))
-
/* Maximum length of the PASSPHRASE, refer to IEEE802.11i specification */
#define PASSPHRASE_MAX_LEN (64)
@@ -1200,7 +1199,7 @@ int main(int argc, FAR char *argv[])
/* Find the command in the g_wapi_command[] list */
wapicmd = NULL;
- for (i = 0; i < NCOMMANDS; i++)
+ for (i = 0; i < nitems(g_wapi_commands); i++)
{
FAR const struct wapi_command_s *cmd = &g_wapi_commands[i];
if (strcmp(cmdname, cmd->name) == 0)