|
|
7a3408 |
From a7232a3278c7eb1363b4795b9cc556fe8b14b950 Mon Sep 17 00:00:00 2001
|
|
|
7a3408 |
Message-Id: <a7232a3278c7eb1363b4795b9cc556fe8b14b950@dist-git>
|
|
|
7a3408 |
From: Martin Kletzander <mkletzan@redhat.com>
|
|
|
7a3408 |
Date: Tue, 18 Aug 2015 17:27:58 -0700
|
|
|
7a3408 |
Subject: [PATCH] util: Add virStringGetFirstWithPrefix
|
|
|
7a3408 |
|
|
|
7a3408 |
https://bugzilla.redhat.com/show_bug.cgi?id=1165580
|
|
|
7a3408 |
|
|
|
7a3408 |
That function takes string list and returns first string in that list
|
|
|
7a3408 |
that starts with the @prefix parameter with that prefix being skipped as
|
|
|
7a3408 |
the caller knows what it starts with (also for easier manipulation in
|
|
|
7a3408 |
future).
|
|
|
7a3408 |
|
|
|
7a3408 |
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
|
|
|
7a3408 |
(cherry picked from commit 1fe69c4656082f48762f69149efc6d9d01d62ce1)
|
|
|
7a3408 |
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
|
|
|
7a3408 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
7a3408 |
---
|
|
|
7a3408 |
src/libvirt_private.syms | 1 +
|
|
|
7a3408 |
src/util/virstring.c | 17 +++++++++++++++++
|
|
|
7a3408 |
src/util/virstring.h | 2 ++
|
|
|
7a3408 |
3 files changed, 20 insertions(+)
|
|
|
7a3408 |
|
|
|
7a3408 |
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
|
|
|
7a3408 |
index 15fa785..a170214 100644
|
|
|
7a3408 |
--- a/src/libvirt_private.syms
|
|
|
7a3408 |
+++ b/src/libvirt_private.syms
|
|
|
7a3408 |
@@ -2174,6 +2174,7 @@ virStrdup;
|
|
|
7a3408 |
virStringArrayHasString;
|
|
|
7a3408 |
virStringFreeList;
|
|
|
7a3408 |
virStringFreeListCount;
|
|
|
7a3408 |
+virStringGetFirstWithPrefix;
|
|
|
7a3408 |
virStringHasControlChars;
|
|
|
7a3408 |
virStringIsEmpty;
|
|
|
7a3408 |
virStringJoin;
|
|
|
7a3408 |
diff --git a/src/util/virstring.c b/src/util/virstring.c
|
|
|
7a3408 |
index 5794f96..31f77cd 100644
|
|
|
7a3408 |
--- a/src/util/virstring.c
|
|
|
7a3408 |
+++ b/src/util/virstring.c
|
|
|
7a3408 |
@@ -238,6 +238,23 @@ virStringArrayHasString(char **strings, const char *needle)
|
|
|
7a3408 |
return false;
|
|
|
7a3408 |
}
|
|
|
7a3408 |
|
|
|
7a3408 |
+char *
|
|
|
7a3408 |
+virStringGetFirstWithPrefix(char **strings, const char *prefix)
|
|
|
7a3408 |
+{
|
|
|
7a3408 |
+ size_t i = 0;
|
|
|
7a3408 |
+
|
|
|
7a3408 |
+ if (!strings)
|
|
|
7a3408 |
+ return NULL;
|
|
|
7a3408 |
+
|
|
|
7a3408 |
+ while (strings[i]) {
|
|
|
7a3408 |
+ if (STRPREFIX(strings[i], prefix))
|
|
|
7a3408 |
+ return strings[i] + strlen(prefix);
|
|
|
7a3408 |
+ i++;
|
|
|
7a3408 |
+ }
|
|
|
7a3408 |
+
|
|
|
7a3408 |
+ return NULL;
|
|
|
7a3408 |
+}
|
|
|
7a3408 |
+
|
|
|
7a3408 |
/* Like strtol, but produce an "int" result, and check more carefully.
|
|
|
7a3408 |
Return 0 upon success; return -1 to indicate failure.
|
|
|
7a3408 |
When END_PTR is NULL, the byte after the final valid digit must be NUL.
|
|
|
7a3408 |
diff --git a/src/util/virstring.h b/src/util/virstring.h
|
|
|
7a3408 |
index e6dcb32..f65a126 100644
|
|
|
7a3408 |
--- a/src/util/virstring.h
|
|
|
7a3408 |
+++ b/src/util/virstring.h
|
|
|
7a3408 |
@@ -47,6 +47,8 @@ void virStringFreeListCount(char **strings, size_t count);
|
|
|
7a3408 |
size_t virStringListLen(const char **strings);
|
|
|
7a3408 |
|
|
|
7a3408 |
bool virStringArrayHasString(char **strings, const char *needle);
|
|
|
7a3408 |
+char *virStringGetFirstWithPrefix(char **strings, const char *prefix)
|
|
|
7a3408 |
+ ATTRIBUTE_NONNULL(2);
|
|
|
7a3408 |
|
|
|
7a3408 |
char *virArgvToString(const char *const *argv);
|
|
|
7a3408 |
|
|
|
7a3408 |
--
|
|
|
7a3408 |
2.5.1
|
|
|
7a3408 |
|