From a4e6e9f433ac0206a10c1c16ac41b7cbe326eca7 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Wed, 9 Oct 2024 17:32:59 +0000 Subject: [PATCH] arch: Dynamically create an array with the supported arches Clang did not like the previous solution. Signed-off-by: Michael Tremer --- src/libpakfire/arch.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/libpakfire/arch.c b/src/libpakfire/arch.c index 03b1cf9ec..5ea79271d 100644 --- a/src/libpakfire/arch.c +++ b/src/libpakfire/arch.c @@ -91,22 +91,35 @@ PAKFIRE_EXPORT int pakfire_arch_supported(const char* name) { return 0; } +static size_t pakfire_num_arches(void) { + size_t i = 0; + + for (const struct pakfire_arch* arch = PAKFIRE_ARCHES; arch->name; arch++) + i++; + + return i; +} + PAKFIRE_EXPORT const char** pakfire_supported_arches(void) { - static const char* supported_arches[] = { - // x86_64 - PAKFIRE_ARCHES[0].name, + const struct pakfire_arch* arch = NULL; + static const char** arches = NULL; - // aarch64 - PAKFIRE_ARCHES[1].name, + if (!arches) { + // Count how many architectures we have + const size_t num_arches = pakfire_num_arches(); + unsigned int i = 0; - // riscv64 - PAKFIRE_ARCHES[2].name, + // Allocate a new array + arches = calloc(num_arches + 1, sizeof(*arches)); + if (!arches) + return NULL; - // Sentinel - NULL, - }; + // Copy all architectures + for (arch = PAKFIRE_ARCHES; arch->name; arch++) + arches[i++] = arch->name; + } - return supported_arches; + return arches; } const char* pakfire_arch_platform(const char* name) { -- 2.47.2