From b8674109ee3a85c1fb362ef7817da30327fb06dd Mon Sep 17 00:00:00 2001 From: Yang Fei Date: Thu, 22 Jul 2021 16:05:00 +0800 Subject: [PATCH] util: Add virFileReadValueUllongQuiet Use function virFileReadValueUllongQuiet to read unsigned long long value without error report. Signed-off-by: Yang Fei Reviewed-by: Michal Privoznik --- src/libvirt_private.syms | 1 + src/util/virfile.c | 24 ++++++++++++++++++++++++ src/util/virfile.h | 2 ++ 3 files changed, 27 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 6bbf551f48..5c7f6bf809 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2244,6 +2244,7 @@ virFileReadValueScaledInt; virFileReadValueString; virFileReadValueUint; virFileReadValueUllong; +virFileReadValueUllongQuiet; virFileRelLinkPointsTo; virFileRemove; virFileRemoveLastComponent; diff --git a/src/util/virfile.c b/src/util/virfile.c index ad491251a2..d6faf7e3d2 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -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: diff --git a/src/util/virfile.h b/src/util/virfile.h index 72368495bf..967c9a9b4f 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -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, ...)