summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@nginx.com>2022-11-07 14:34:58 +0100
committerAlejandro Colomar <alx@nginx.com>2023-05-23 20:37:51 +0200
commitb1938eb20207368cedd9b767138e9cda43a571fc (patch)
tree19a5f045dae02e2a0f592fc964b2d0e9d0bccdc6
parent27af6dcb48d8e7ba5c07eba8f0157262222bcf18 (diff)
Core: added macro to calculate the length of an array.
This macro abstracts calculating how many items are there in an array. Since recent versions of GCC and Clang provide a warning if we pass a pointer to the construct in this macro, it is safe to use without any further checks that the argument is an array. Link: <https://stackoverflow.com/a/57537491> Cc: Andrew Clayton <a.clayton@nginx.com> Cc: Zhidao Hong <z.hong@f5.com> Signed-off-by: Alejandro Colomar <alx@nginx.com>
-rw-r--r--src/core/ngx_core.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/core/ngx_core.h b/src/core/ngx_core.h
index 88db7dc98..229714fdf 100644
--- a/src/core/ngx_core.h
+++ b/src/core/ngx_core.h
@@ -109,6 +109,9 @@ typedef void (*ngx_connection_handler_pt)(ngx_connection_t *c);
#define ngx_max(val1, val2) ((val1 < val2) ? (val2) : (val1))
#define ngx_min(val1, val2) ((val1 > val2) ? (val2) : (val1))
+#define ngx_nitems(arr) (sizeof((arr)) / sizeof((arr)[0]))
+
+
void ngx_cpuinfo(void);
#if (NGX_HAVE_OPENAT)