Blob Blame History Raw
From 7bf6cf5632fbdf83a37c52c40b7b982094b5c668 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose@redhat.com>
Date: Mon, 20 Feb 2017 17:28:51 +0100
Subject: [PATCH 03/15] util: move string_in_list to util_ext
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

To be able to include string_in_list() without additional
dependencies it is moved into a separate file.

Related to https://pagure.io/SSSD/sssd/issue/3050

Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
---
 src/util/util.c     | 20 --------------------
 src/util/util_ext.c | 22 ++++++++++++++++++++++
 2 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/src/util/util.c b/src/util/util.c
index 9d6202f695d516f20d648621da81a2d5e746daa5..f0e8f9dd6a4bceed6befb74c57aa066b19a72bb7 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -617,26 +617,6 @@ errno_t add_string_to_list(TALLOC_CTX *mem_ctx, const char *string,
     return EOK;
 }
 
-bool string_in_list(const char *string, char **list, bool case_sensitive)
-{
-    size_t c;
-    int(*compare)(const char *s1, const char *s2);
-
-    if (string == NULL || list == NULL || *list == NULL) {
-        return false;
-    }
-
-    compare = case_sensitive ? strcmp : strcasecmp;
-
-    for (c = 0; list[c] != NULL; c++) {
-        if (compare(string, list[c]) == 0) {
-            return true;
-        }
-    }
-
-    return false;
-}
-
 void safezero(void *data, size_t size)
 {
     volatile uint8_t *p = data;
diff --git a/src/util/util_ext.c b/src/util/util_ext.c
index fceb8c873a26471d476b39d5d4e567c445ed8d0b..04dc02a8adf32bd0590fe6eba230658e67d0a362 100644
--- a/src/util/util_ext.c
+++ b/src/util/util_ext.c
@@ -24,6 +24,8 @@
 #include <stdbool.h>
 #include <errno.h>
 #include <ctype.h>
+#include <string.h>
+#include <strings.h>
 
 #define EOK 0
 
@@ -119,3 +121,23 @@ done:
     talloc_free(tmp_ctx);
     return ret;
 }
+
+bool string_in_list(const char *string, char **list, bool case_sensitive)
+{
+    size_t c;
+    int(*compare)(const char *s1, const char *s2);
+
+    if (string == NULL || list == NULL || *list == NULL) {
+        return false;
+    }
+
+    compare = case_sensitive ? strcmp : strcasecmp;
+
+    for (c = 0; list[c] != NULL; c++) {
+        if (compare(string, list[c]) == 0) {
+            return true;
+        }
+    }
+
+    return false;
+}
-- 
2.9.3