[PATCH nft 1/3] nft: add NFT_ARRAY_SIZE() helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add NFT_ARRAY_SIZE() macro, commonly known as ARRAY_SIZE() (or G_N_ELEMENTS()).

<nft.h> is the right place for macros and static-inline functions. It is
included in *every* C sources, as it only depends on libc headers and
<config.h>. NFT_ARRAY_SIZE() is part of the basic toolset, that should
be available everywhere.

Signed-off-by: Thomas Haller <thaller@xxxxxxxxxx>
---
 include/nft.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/nft.h b/include/nft.h
index 9384054c11c8..4463b5c0fa4a 100644
--- a/include/nft.h
+++ b/include/nft.h
@@ -8,4 +8,6 @@
 #include <stdint.h>
 #include <stdlib.h>
 
+#define NFT_ARRAY_SIZE(arr) (sizeof(arr)/sizeof((arr)[0]))
+
 #endif /* NFTABLES_NFT_H */
-- 
2.41.0




[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux