summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/config.h5
-rw-r--r--src/fsade.c3
-rw-r--r--tests/trie.c3
3 files changed, 8 insertions, 3 deletions
diff --git a/src/config.h b/src/config.h
index 0822e3c..4a49b75 100644
--- a/src/config.h
+++ b/src/config.h
@@ -155,6 +155,11 @@
# define BFS_FALLTHROUGH ((void)0)
#endif
+/**
+ * Get the length of an array.
+ */
+#define BFS_COUNTOF(array) (sizeof(array) / sizeof(0[array]))
+
// Lower bound on BFS_FLEX_SIZEOF()
#define BFS_FLEX_LB(type, member, length) (offsetof(type, member) + sizeof(((type *)NULL)->member[0]) * (length))
diff --git a/src/fsade.c b/src/fsade.c
index a609b97..45969d1 100644
--- a/src/fsade.c
+++ b/src/fsade.c
@@ -206,7 +206,6 @@ int bfs_check_acl(const struct BFTW *ftwbuf) {
ACL_TYPE_NFS4,
#endif
};
- static const size_t n_acl_types = sizeof(acl_types)/sizeof(acl_types[0]);
if (ftwbuf->type == BFS_LNK) {
return 0;
@@ -215,7 +214,7 @@ int bfs_check_acl(const struct BFTW *ftwbuf) {
const char *path = fake_at(ftwbuf);
int ret = -1, error = 0;
- for (size_t i = 0; i < n_acl_types && ret <= 0; ++i) {
+ for (size_t i = 0; i < BFS_COUNTOF(acl_types) && ret <= 0; ++i) {
acl_type_t type = acl_types[i];
if (type == ACL_TYPE_DEFAULT && ftwbuf->type != BFS_DIR) {
diff --git a/tests/trie.c b/tests/trie.c
index 6bc7549..88e92da 100644
--- a/tests/trie.c
+++ b/tests/trie.c
@@ -17,6 +17,7 @@
#undef NDEBUG
#include "../src/trie.h"
+#include "../src/config.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
@@ -50,7 +51,7 @@ const char *keys[] = {
">>>",
};
-const size_t nkeys = sizeof(keys) / sizeof(keys[0]);
+const size_t nkeys = BFS_COUNTOF(keys);
int main(void) {
struct trie trie;