]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: Add virFileReadValueUllongQuiet
authorYang Fei <yangfei85@huawei.com>
Thu, 22 Jul 2021 08:05:00 +0000 (16:05 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 27 Jul 2021 08:29:20 +0000 (10:29 +0200)
Use function virFileReadValueUllongQuiet to read unsigned long
long value without error report.

Signed-off-by: Yang Fei <yangfei85@huawei.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/libvirt_private.syms
src/util/virfile.c
src/util/virfile.h

index 6bbf551f48fed3039f5f1d53730fd8219e792385..5c7f6bf8092a0c45b8d7267a9ec1c5cdffa5a979 100644 (file)
@@ -2244,6 +2244,7 @@ virFileReadValueScaledInt;
 virFileReadValueString;
 virFileReadValueUint;
 virFileReadValueUllong;
+virFileReadValueUllongQuiet;
 virFileRelLinkPointsTo;
 virFileRemove;
 virFileRemoveLastComponent;
index ad491251a2f2a1525ebb10a375b30b7d0b68599d..d6faf7e3d2dabc40f58f6166b4f0287c307f5e17 100644 (file)
@@ -4065,6 +4065,30 @@ virFileReadValueUllong(unsigned long long *value, const char *format, ...)
     return 0;
 }
 
+int
+virFileReadValueUllongQuiet(unsigned long long *value, const char *format, ...)
+{
+    g_autofree char *str = NULL;
+    g_autofree char *path = NULL;
+    va_list ap;
+
+    va_start(ap, format);
+    path = g_strdup_vprintf(format, ap);
+    va_end(ap);
+
+    if (!virFileExists(path))
+        return -2;
+
+    if (virFileReadAllQuiet(path, VIR_INT64_STR_BUFLEN, &str) < 0)
+        return -1;
+
+    virStringTrimOptionalNewline(str);
+
+    if (virStrToLong_ullp(str, NULL, 10, value) < 0)
+        return -1;
+
+    return 0;
+}
 
 /**
  * virFileReadValueScaledInt:
index 72368495bf52914c4e119e74ad0db1dcd11fb968..967c9a9b4f157b11d006368a58bc6256a1358e34 100644 (file)
@@ -339,6 +339,8 @@ int virFileReadValueUint(unsigned int *value, const char *format, ...)
  G_GNUC_PRINTF(2, 3);
 int virFileReadValueUllong(unsigned long long *value, const char *format, ...)
  G_GNUC_PRINTF(2, 3);
+int virFileReadValueUllongQuiet(unsigned long long *value, const char *format, ...)
+ G_GNUC_PRINTF(2, 3);
 int virFileReadValueBitmap(virBitmap **value, const char *format, ...)
  G_GNUC_PRINTF(2, 3);
 int virFileReadValueScaledInt(unsigned long long *value, const char *format, ...)