Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx> --- src/libvirt_private.syms | 1 + src/util/virfile.c | 28 ++++++++++++++++++++++++++++ src/util/virfile.h | 1 + 3 files changed, 30 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b551cb86a68e..9e61accda3fc 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1631,6 +1631,7 @@ virFileReadLimFD; virFileReadLink; virFileReadValueBitmap; virFileReadValueInt; +virFileReadValueScaledInt; virFileReadValueUint; virFileRelLinkPointsTo; virFileRemove; diff --git a/src/util/virfile.c b/src/util/virfile.c index c0f448d3437d..93fc81f2cfab 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -3880,6 +3880,34 @@ virFileReadValueUint(const char *path, unsigned int *value) * fine. */ int +virFileReadValueScaledInt(const char *path, unsigned long long *value) +{ + char *str = NULL; + char *endp = NULL; + int ret = -1; + + if (!virFileExists(path)) + return -2; + + if (virFileReadAll(path, INT_STRLEN_BOUND(*value), &str) < 0) + return -1; + + virStringTrimOptionalNewline(str); + + if (virStrToLong_ullp(str, &endp, 10, value) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid unsigned scaled integer value '%s' in file '%s'"), + str, path); + goto cleanup; + } + + ret = virScaleInteger(value, endp, 1024, ULLONG_MAX); + cleanup: + VIR_FREE(str); + return ret; +} + +int virFileReadValueBitmap(const char *path, int maxlen, virBitmapPtr *value) diff --git a/src/util/virfile.h b/src/util/virfile.h index ba1c57c06a8e..406569bdb7e9 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -338,6 +338,7 @@ int virFileComparePaths(const char *p1, const char *p2); int virFileReadValueInt(const char *path, int *value); int virFileReadValueUint(const char *path, unsigned int *value); +int virFileReadValueScaledInt(const char *path, unsigned long long *value); int virFileReadValueBitmap(const char *path, int maxlen, virBitmapPtr *value); #endif /* __VIR_FILE_H */ -- 2.12.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list