diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-03-05 06:56:15 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-03-07 05:27:16 +0100 |
commit | 5716c27e1f52d2aba9dd02916c01d6271d9d0b16 (patch) | |
tree | 20d05695685f3b36806cb83d9898ec66ae1d7ceb /src/basic/macro.h | |
parent | Merge pull request #26669 from YHNdnzj/journalctl-lines-since-until (diff) | |
download | systemd-5716c27e1f52d2aba9dd02916c01d6271d9d0b16.tar.xz systemd-5716c27e1f52d2aba9dd02916c01d6271d9d0b16.zip |
macro: introduce FOREACH_ARRAY() macro
The pattern that runs all array element is quite common.
But, sometimes, the number of element may be in a signed integer, or the
array may be NULL.
Diffstat (limited to 'src/basic/macro.h')
-rw-r--r-- | src/basic/macro.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/basic/macro.h b/src/basic/macro.h index 2425d27819..3de319d880 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -297,6 +297,13 @@ static inline int __coverity_check_and_return__(int condition) { p != (typeof(p)) POINTER_MAX; \ p = *(++_l)) +#define _FOREACH_ARRAY(i, array, num, m, s) \ + for (typeof(num) m = (num); m > 0; m = 0) \ + for (typeof(array[0]) *s = (array), *i = s; s && i < s + m; i++) + +#define FOREACH_ARRAY(i, array, num) \ + _FOREACH_ARRAY(i, array, num, UNIQ_T(m, UNIQ), UNIQ_T(s, UNIQ)) + #define DEFINE_TRIVIAL_DESTRUCTOR(name, type, func) \ static inline void name(type *p) { \ func(p); \ |