From: Rohan Dutta Date: Fri, 21 Mar 2025 09:38:04 +0000 (+0530) Subject: int_array: Add a function to check for equality X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=56f7d76d745addac7666e8e5c0bd4ac84c902f5e;p=thirdparty%2Fhostap.git int_array: Add a function to check for equality Add int_array_equal() to allow comparison of two int_array instances. Return true if both arrays included the same set of integers. Co-developed-by: Pooventhiran G Signed-off-by: Pooventhiran G Signed-off-by: Rohan Dutta --- diff --git a/src/utils/common.c b/src/utils/common.c index d5e51a792..eb5a68b49 100644 --- a/src/utils/common.c +++ b/src/utils/common.c @@ -1003,6 +1003,28 @@ bool int_array_includes(const int *arr, int val) } +bool int_array_equal(const int *a, const int *b) +{ + size_t alen, blen, i; + + if (!a || !b) + return false; + + alen = int_array_len(a); + blen = int_array_len(b); + + if (alen != blen) + return false; + + for (i = 0; i <= alen; i++) { + if (!int_array_includes(b, a[i])) + return false; + } + + return true; +} + + void str_clear_free(char *str) { if (str) { diff --git a/src/utils/common.h b/src/utils/common.h index f1c46599e..d7b3600f2 100644 --- a/src/utils/common.h +++ b/src/utils/common.h @@ -595,6 +595,7 @@ void int_array_concat(int **res, const int *a); void int_array_sort_unique(int *a); void int_array_add_unique(int **res, int a); bool int_array_includes(const int *arr, int val); +bool int_array_equal(const int *a, const int *b); #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))