[PATCH 03/22] util: typedparam: Move and unexport virTypedParameterAssignFromStr

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

 



The function is only used as a helper in virTypedParamsAddFromString.
Make it static and move it to virtypedparam-public.c.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/libvirt_private.syms        |  1 -
 src/util/virtypedparam-public.c | 95 +++++++++++++++++++++++++++++++++
 src/util/virtypedparam.c        | 93 --------------------------------
 src/util/virtypedparam.h        |  6 ---
 4 files changed, 95 insertions(+), 100 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 39812227aa..8af9e7c95e 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -3229,7 +3229,6 @@ virTPMSwtpmSetupFeatureTypeFromString;

 # util/virtypedparam.h
 virTypedParameterAssign;
-virTypedParameterAssignFromStr;
 virTypedParameterToString;
 virTypedParameterTypeFromString;
 virTypedParameterTypeToString;
diff --git a/src/util/virtypedparam-public.c b/src/util/virtypedparam-public.c
index 585e851f38..fb7f178c6c 100644
--- a/src/util/virtypedparam-public.c
+++ b/src/util/virtypedparam-public.c
@@ -25,6 +25,101 @@

 #define VIR_FROM_THIS VIR_FROM_NONE

+/* Assign name, type, and convert the argument from a const string.
+ * In case of a string, the string is copied.
+ * Return 0 on success, -1 after an error message on failure.  */
+static int
+virTypedParameterAssignFromStr(virTypedParameterPtr param,
+                               const char *name,
+                               int type,
+                               const char *val)
+{
+    int ret = -1;
+
+    if (!val) {
+        virReportError(VIR_ERR_INVALID_ARG, _("NULL value for field '%s'"),
+                       name);
+        goto cleanup;
+    }
+
+    if (virStrcpyStatic(param->field, name) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, _("Field name '%s' too long"),
+                       name);
+        goto cleanup;
+    }
+
+    param->type = type;
+    switch (type) {
+    case VIR_TYPED_PARAM_INT:
+        if (virStrToLong_i(val, NULL, 10, &param->value.i) < 0) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("Invalid value for field '%s': expected int"),
+                           name);
+            goto cleanup;
+        }
+        break;
+    case VIR_TYPED_PARAM_UINT:
+        if (virStrToLong_ui(val, NULL, 10, &param->value.ui) < 0) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("Invalid value for field '%s': "
+                             "expected unsigned int"),
+                           name);
+            goto cleanup;
+        }
+        break;
+    case VIR_TYPED_PARAM_LLONG:
+        if (virStrToLong_ll(val, NULL, 10, &param->value.l) < 0) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("Invalid value for field '%s': "
+                             "expected long long"),
+                           name);
+            goto cleanup;
+        }
+        break;
+    case VIR_TYPED_PARAM_ULLONG:
+        if (virStrToLong_ull(val, NULL, 10, &param->value.ul) < 0) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("Invalid value for field '%s': "
+                             "expected unsigned long long"),
+                           name);
+            goto cleanup;
+        }
+        break;
+    case VIR_TYPED_PARAM_DOUBLE:
+        if (virStrToDouble(val, NULL, &param->value.d) < 0) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("Invalid value for field '%s': "
+                             "expected double"),
+                           name);
+            goto cleanup;
+        }
+        break;
+    case VIR_TYPED_PARAM_BOOLEAN:
+        if (STRCASEEQ(val, "true") || STREQ(val, "1")) {
+            param->value.b = true;
+        } else if (STRCASEEQ(val, "false") || STREQ(val, "0")) {
+            param->value.b = false;
+        } else {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("Invalid boolean value for field '%s'"), name);
+            goto cleanup;
+        }
+        break;
+    case VIR_TYPED_PARAM_STRING:
+        if (VIR_STRDUP(param->value.s, val) < 0)
+            goto cleanup;
+        break;
+    default:
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("unexpected type %d for field %s"), type, name);
+        goto cleanup;
+    }
+
+    ret = 0;
+ cleanup:
+    return ret;
+}
+
 /* The following APIs are public and their signature may never change. */

 /**
diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c
index acf8c39602..d9f8203796 100644
--- a/src/util/virtypedparam.c
+++ b/src/util/virtypedparam.c
@@ -260,99 +260,6 @@ virTypedParameterAssign(virTypedParameterPtr param, const char *name,
     return ret;
 }

-/* Assign name, type, and convert the argument from a const string.
- * In case of a string, the string is copied.
- * Return 0 on success, -1 after an error message on failure.  */
-int
-virTypedParameterAssignFromStr(virTypedParameterPtr param, const char *name,
-                               int type, const char *val)
-{
-    int ret = -1;
-
-    if (!val) {
-        virReportError(VIR_ERR_INVALID_ARG, _("NULL value for field '%s'"),
-                       name);
-        goto cleanup;
-    }
-
-    if (virStrcpyStatic(param->field, name) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, _("Field name '%s' too long"),
-                       name);
-        goto cleanup;
-    }
-
-    param->type = type;
-    switch (type) {
-    case VIR_TYPED_PARAM_INT:
-        if (virStrToLong_i(val, NULL, 10, &param->value.i) < 0) {
-            virReportError(VIR_ERR_INVALID_ARG,
-                           _("Invalid value for field '%s': expected int"),
-                           name);
-            goto cleanup;
-        }
-        break;
-    case VIR_TYPED_PARAM_UINT:
-        if (virStrToLong_ui(val, NULL, 10, &param->value.ui) < 0) {
-            virReportError(VIR_ERR_INVALID_ARG,
-                           _("Invalid value for field '%s': "
-                             "expected unsigned int"),
-                           name);
-            goto cleanup;
-        }
-        break;
-    case VIR_TYPED_PARAM_LLONG:
-        if (virStrToLong_ll(val, NULL, 10, &param->value.l) < 0) {
-            virReportError(VIR_ERR_INVALID_ARG,
-                           _("Invalid value for field '%s': "
-                             "expected long long"),
-                           name);
-            goto cleanup;
-        }
-        break;
-    case VIR_TYPED_PARAM_ULLONG:
-        if (virStrToLong_ull(val, NULL, 10, &param->value.ul) < 0) {
-            virReportError(VIR_ERR_INVALID_ARG,
-                           _("Invalid value for field '%s': "
-                             "expected unsigned long long"),
-                           name);
-            goto cleanup;
-        }
-        break;
-    case VIR_TYPED_PARAM_DOUBLE:
-        if (virStrToDouble(val, NULL, &param->value.d) < 0) {
-            virReportError(VIR_ERR_INVALID_ARG,
-                           _("Invalid value for field '%s': "
-                             "expected double"),
-                           name);
-            goto cleanup;
-        }
-        break;
-    case VIR_TYPED_PARAM_BOOLEAN:
-        if (STRCASEEQ(val, "true") || STREQ(val, "1")) {
-            param->value.b = true;
-        } else if (STRCASEEQ(val, "false") || STREQ(val, "0")) {
-            param->value.b = false;
-        } else {
-            virReportError(VIR_ERR_INVALID_ARG,
-                           _("Invalid boolean value for field '%s'"), name);
-            goto cleanup;
-        }
-        break;
-    case VIR_TYPED_PARAM_STRING:
-        if (VIR_STRDUP(param->value.s, val) < 0)
-            goto cleanup;
-        break;
-    default:
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("unexpected type %d for field %s"), type, name);
-        goto cleanup;
-    }
-
-    ret = 0;
- cleanup:
-    return ret;
-}
-

 /**
  * virTypedParamsReplaceString:
diff --git a/src/util/virtypedparam.h b/src/util/virtypedparam.h
index f9d22b24fb..cad6953f5d 100644
--- a/src/util/virtypedparam.h
+++ b/src/util/virtypedparam.h
@@ -85,12 +85,6 @@ int virTypedParameterAssign(virTypedParameterPtr param, const char *name,
                             int type, /* TYPE arg */ ...)
     ATTRIBUTE_RETURN_CHECK;

-int virTypedParameterAssignFromStr(virTypedParameterPtr param,
-                                   const char *name,
-                                   int type,
-                                   const char *val)
-    ATTRIBUTE_RETURN_CHECK;
-
 int virTypedParamsReplaceString(virTypedParameterPtr *params,
                                 int *nparams,
                                 const char *name,
-- 
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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