[libvirt PATCH 2/4] util: virParseVersionString: move to virstring.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx>
---
 src/libvirt_private.syms |  2 +-
 src/util/virstring.c     | 47 ++++++++++++++++++++++++++++++++++++++++
 src/util/virstring.h     |  4 ++++
 src/util/virutil.c       | 46 ---------------------------------------
 src/util/virutil.h       |  3 ---
 5 files changed, 52 insertions(+), 50 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index bc6fa191bf..38506c52c6 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -3302,6 +3302,7 @@ virStorageFileParseBackingStoreStr;
 
 
 # util/virstring.h
+virParseVersionString;
 virSkipSpaces;
 virSkipSpacesAndBackslash;
 virSkipSpacesBackwards;
@@ -3546,7 +3547,6 @@ virMemoryLimitIsSet;
 virMemoryLimitTruncate;
 virMemoryMaxValue;
 virParseOwnershipIds;
-virParseVersionString;
 virPipe;
 virPipeNonBlock;
 virPipeQuiet;
diff --git a/src/util/virstring.c b/src/util/virstring.c
index cee56debca..a7ce566963 100644
--- a/src/util/virstring.c
+++ b/src/util/virstring.c
@@ -1019,3 +1019,50 @@ int virStringParseYesNo(const char *str, bool *result)
 
     return 0;
 }
+
+
+/**
+ * virParseVersionString:
+ * @str: const char pointer to the version string
+ * @version: unsigned long pointer to output the version number
+ * @allowMissing: true to treat 3 like 3.0.0, false to error out on
+ * missing minor or micro
+ *
+ * Parse an unsigned version number from a version string. Expecting
+ * 'major.minor.micro' format, ignoring an optional suffix.
+ *
+ * The major, minor and micro numbers are encoded into a single version number:
+ *
+ *   1000000 * major + 1000 * minor + micro
+ *
+ * Returns the 0 for success, -1 for error.
+ */
+int
+virParseVersionString(const char *str, unsigned long *version,
+                      bool allowMissing)
+{
+    unsigned int major, minor = 0, micro = 0;
+    char *tmp;
+
+    if (virStrToLong_ui(str, &tmp, 10, &major) < 0)
+        return -1;
+
+    if (!allowMissing && *tmp != '.')
+        return -1;
+
+    if ((*tmp == '.') && virStrToLong_ui(tmp + 1, &tmp, 10, &minor) < 0)
+        return -1;
+
+    if (!allowMissing && *tmp != '.')
+        return -1;
+
+    if ((*tmp == '.') && virStrToLong_ui(tmp + 1, &tmp, 10, &micro) < 0)
+        return -1;
+
+    if (major > UINT_MAX / 1000000 || minor > 999 || micro > 999)
+        return -1;
+
+    *version = 1000000 * major + 1000 * minor + micro;
+
+    return 0;
+}
diff --git a/src/util/virstring.h b/src/util/virstring.h
index 45f07ddd7a..1dbeb7445f 100644
--- a/src/util/virstring.h
+++ b/src/util/virstring.h
@@ -135,3 +135,7 @@ int virStringParsePort(const char *str,
 int virStringParseYesNo(const char *str,
                         bool *result)
     G_GNUC_WARN_UNUSED_RESULT;
+
+int virParseVersionString(const char *str,
+                          unsigned long *version,
+                          bool allowMissing);
diff --git a/src/util/virutil.c b/src/util/virutil.c
index 8a6efd4d5c..fe5500726e 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -231,52 +231,6 @@ virScaleInteger(unsigned long long *value, const char *suffix,
 }
 
 
-/**
- * virParseVersionString:
- * @str: const char pointer to the version string
- * @version: unsigned long pointer to output the version number
- * @allowMissing: true to treat 3 like 3.0.0, false to error out on
- * missing minor or micro
- *
- * Parse an unsigned version number from a version string. Expecting
- * 'major.minor.micro' format, ignoring an optional suffix.
- *
- * The major, minor and micro numbers are encoded into a single version number:
- *
- *   1000000 * major + 1000 * minor + micro
- *
- * Returns the 0 for success, -1 for error.
- */
-int
-virParseVersionString(const char *str, unsigned long *version,
-                      bool allowMissing)
-{
-    unsigned int major, minor = 0, micro = 0;
-    char *tmp;
-
-    if (virStrToLong_ui(str, &tmp, 10, &major) < 0)
-        return -1;
-
-    if (!allowMissing && *tmp != '.')
-        return -1;
-
-    if ((*tmp == '.') && virStrToLong_ui(tmp + 1, &tmp, 10, &minor) < 0)
-        return -1;
-
-    if (!allowMissing && *tmp != '.')
-        return -1;
-
-    if ((*tmp == '.') && virStrToLong_ui(tmp + 1, &tmp, 10, &micro) < 0)
-        return -1;
-
-    if (major > UINT_MAX / 1000000 || minor > 999 || micro > 999)
-        return -1;
-
-    *version = 1000000 * major + 1000 * minor + micro;
-
-    return 0;
-}
-
 /**
  * Format @val as a base-10 decimal number, in the
  * buffer @buf of size @buflen. To allocate a suitable
diff --git a/src/util/virutil.h b/src/util/virutil.h
index 6bb55918ad..6adebde242 100644
--- a/src/util/virutil.h
+++ b/src/util/virutil.h
@@ -44,9 +44,6 @@ int virScaleInteger(unsigned long long *value, const char *suffix,
                     unsigned long long scale, unsigned long long limit)
     ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT;
 
-int virParseVersionString(const char *str, unsigned long *version,
-                          bool allowMissing);
-
 char *virFormatIntDecimal(char *buf, size_t buflen, int val)
     ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT;
 
-- 
2.34.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux