]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
string-util: move startswith_strv to strv
authorMike Yuan <me@yhndnzj.com>
Thu, 4 Jan 2024 08:44:15 +0000 (16:44 +0800)
committerMike Yuan <me@yhndnzj.com>
Thu, 4 Jan 2024 08:49:05 +0000 (16:49 +0800)
src/basic/string-util.c
src/basic/string-util.h
src/basic/strv.c
src/basic/strv.h

index 3c34d6b455aca66faf99b29c9001ae9f85d8e697..8b039ebd9843dd258ea8454c3d10d56c28a5d1f0 100644 (file)
@@ -1420,18 +1420,6 @@ char *find_line_startswith(const char *haystack, const char *needle) {
         return p + strlen(needle);
 }
 
-char *startswith_strv(const char *string, char **strv) {
-        char *found = NULL;
-
-        STRV_FOREACH(i, strv) {
-                found = startswith(string, *i);
-                if (found)
-                        break;
-        }
-
-        return found;
-}
-
 bool version_is_valid(const char *s) {
         if (isempty(s))
                 return false;
index bf427cd7f7a67144c5272504e93739c3ddf8acb0..e162765aa7174a8113952e2b606b5c22b09cb482 100644 (file)
@@ -291,11 +291,6 @@ char *strdupcspn(const char *a, const char *reject);
 
 char *find_line_startswith(const char *haystack, const char *needle);
 
-char *startswith_strv(const char *string, char **strv);
-
-#define STARTSWITH_SET(p, ...)                                  \
-        startswith_strv(p, STRV_MAKE(__VA_ARGS__))
-
 bool version_is_valid(const char *s);
 
 bool version_is_valid_versionspec(const char *s);
index 43a4f569bd25e492fd3f897058268b8f02972c14..ff2f672c103633a7aca591cf94ff0c62dcea8759 100644 (file)
@@ -706,6 +706,16 @@ int strv_extendf(char ***l, const char *format, ...) {
         return strv_consume(l, x);
 }
 
+char* startswith_strv(const char *s, char * const *l) {
+        STRV_FOREACH(i, l) {
+                char *found = startswith(s, *i);
+                if (found)
+                        return found;
+        }
+
+        return NULL;
+}
+
 char** strv_reverse(char **l) {
         size_t n;
 
index 18df0f23f246fe3ff0c02d588da5843b1534abd0..66fa0cd2e441b4d1fe54c049e6253d21c90818e5 100644 (file)
@@ -159,6 +159,11 @@ static inline void strv_print(char * const *l) {
         strv_print_full(l, NULL);
 }
 
+char* startswith_strv(const char *s, char * const *l);
+
+#define STARTSWITH_SET(p, ...)                                  \
+        startswith_strv(p, STRV_MAKE(__VA_ARGS__))
+
 #define strv_from_stdarg_alloca(first)                          \
         ({                                                      \
                 char **_l;                                      \