Use function virFileReadValueUllongQuiet to read unsigned long long value without error report. Signed-off-by: Yang Fei <yangfei85@xxxxxxxxxx> --- 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 4bc2974e7f..5429a82a7c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2242,6 +2242,7 @@ virFileReadValueScaledInt; virFileReadValueString; virFileReadValueUint; virFileReadValueUllong; +virFileReadValueUllongQuiet; virFileRelLinkPointsTo; virFileRemove; virFileRemoveLastComponent; diff --git a/src/util/virfile.c b/src/util/virfile.c index 723e1ca6e5..70737f4751 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, ...) -- 2.23.0