From 5bd8d352506201835b103514fbeffcc8d6958b73 Mon Sep 17 00:00:00 2001 From: Duncan Overbruck Date: Fri, 1 Sep 2023 16:15:13 +0200 Subject: [PATCH] replace __arraycount with ARRAY_SIZE --- include/macro.h | 2 ++ include/xbps_api_impl.h | 4 ---- lib/conf.c | 3 ++- lib/pkgdb_conversion.c | 12 +++++++----- lib/transaction_files.c | 5 +++-- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/include/macro.h b/include/macro.h index 1316f758..cbf91ea9 100644 --- a/include/macro.h +++ b/include/macro.h @@ -37,4 +37,6 @@ # define HIDDEN #endif +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + #endif /*!XBPS_MACRO_H*/ diff --git a/include/xbps_api_impl.h b/include/xbps_api_impl.h index 02ba9bb0..42e99b0c 100644 --- a/include/xbps_api_impl.h +++ b/include/xbps_api_impl.h @@ -39,10 +39,6 @@ ARCHIVE_EXTRACT_UNLINK #define FEXTRACT_FLAGS ARCHIVE_EXTRACT_OWNER | EXTRACT_FLAGS -#ifndef __arraycount -#define __arraycount(x) (sizeof(x) / sizeof(*x)) -#endif - /** * @private */ diff --git a/lib/conf.c b/lib/conf.c index 24a2131c..62adfddf 100644 --- a/lib/conf.c +++ b/lib/conf.c @@ -42,6 +42,7 @@ #include #include +#include "macro.h" #include "xbps_api_impl.h" /** @@ -212,7 +213,7 @@ parse_option(char *line, size_t linelen, char **valp, size_t *vallen) if (*p != '=') return KEY_ERROR; - result = bsearch(&needle, keys, __arraycount(keys), sizeof(struct key), cmpkey); + result = bsearch(&needle, keys, ARRAY_SIZE(keys), sizeof(struct key), cmpkey); if (result == NULL) return KEY_ERROR; diff --git a/lib/pkgdb_conversion.c b/lib/pkgdb_conversion.c index c9be47d6..079e7a1b 100644 --- a/lib/pkgdb_conversion.c +++ b/lib/pkgdb_conversion.c @@ -23,14 +23,16 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include + +#include +#include #include +#include #include #include -#include -#include -#include +#include "macro.h" #include "xbps_api_impl.h" static int @@ -115,7 +117,7 @@ pkgdb038(struct xbps_handle *xhp, const char *opkgdb_plist) key = xbps_dictionary_keysym_cstring_nocopy(obj2); curobj = xbps_dictionary_get_keysym(pkgmetad, obj2); - for (uint8_t i = 0; i < __arraycount(excluded); i++) { + for (uint8_t i = 0; i < ARRAY_SIZE(excluded); i++) { if (strcmp(excluded[i], key) == 0) { skip = true; break; diff --git a/lib/transaction_files.c b/lib/transaction_files.c index 970dfac3..c98411cb 100644 --- a/lib/transaction_files.c +++ b/lib/transaction_files.c @@ -32,8 +32,9 @@ #include #include -#include "xbps_api_impl.h" +#include "macro.h" #include "uthash.h" +#include "xbps_api_impl.h" enum type { TYPE_LINK = 1, @@ -296,7 +297,7 @@ collect_obsoletes(struct xbps_handle *xhp) /* * Make sure to not remove any symlink of root directory. */ - for (uint8_t x = 0; x < __arraycount(basesymlinks); x++) { + for (uint8_t x = 0; x < ARRAY_SIZE(basesymlinks); x++) { if (strcmp(item->file+1, basesymlinks[x]) == 0) { found = true; break;