[PATCH 001/103] virJSONValueObjectAddVArgs: Add 'k' convertor for formatting non-negative integers

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

 



In many cases we use a signed value, but use the sign to note that it
was not assigned. For converting to JSON objects it will be handy to
have possibility to do this automatically.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/util/virjson.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/util/virjson.c b/src/util/virjson.c
index 9adcea4fff..70ea71b505 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -115,6 +115,7 @@ virJSONValueGetType(const virJSONValue *value)
  *
  * i: signed integer value
  * j: signed integer value, error if negative
+ * k: signed integer value, omitted if negative
  * z: signed integer value, omitted if zero
  * y: signed integer value, omitted if zero, error if negative
  *
@@ -189,6 +190,7 @@ virJSONValueObjectAddVArgs(virJSONValue *obj,

         case 'z':
         case 'y':
+        case 'k':
         case 'j':
         case 'i': {
             int val = va_arg(args, int);
@@ -200,7 +202,10 @@ virJSONValueObjectAddVArgs(virJSONValue *obj,
                 return -1;
             }

-            if (!val && (type == 'z' || type == 'y'))
+            if (val == 0 && (type == 'z' || type == 'y'))
+                continue;
+
+            if (val < 0 && type == 'k')
                 continue;

             rc = virJSONValueObjectAppendNumberInt(obj, key, val);
-- 
2.31.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