From fe180cbf5d5747388720a989a5aa784b737d4433 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Thu, 4 Nov 2021 13:30:27 +0000 Subject: [PATCH] trivial: Add fu_udev_device_get_sysfs_attr_uint64() for future code --- libfwupdplugin/fu-udev-device.c | 35 +++++++++++++++++++++++++++++++++ libfwupdplugin/fu-udev-device.h | 5 +++++ libfwupdplugin/fwupdplugin.map | 1 + 3 files changed, 41 insertions(+) diff --git a/libfwupdplugin/fu-udev-device.c b/libfwupdplugin/fu-udev-device.c index cbb31cf76..16b591c38 100644 --- a/libfwupdplugin/fu-udev-device.c +++ b/libfwupdplugin/fu-udev-device.c @@ -1594,6 +1594,41 @@ fu_udev_device_get_sysfs_attr(FuUdevDevice *self, const gchar *attr, GError **er #endif } +/** + * fu_udev_device_get_sysfs_attr_uint64: + * @self: a #FuUdevDevice + * @attr: name of attribute to get + * @value: (out) (optional): value to return + * @error: (nullable): optional return location for an error + * + * Reads an arbitrary sysfs attribute 'attr' associated with UDEV device as a uint64. + * + * Returns: %TRUE for success + * + * Since: 1.7.2 + **/ +gboolean +fu_udev_device_get_sysfs_attr_uint64(FuUdevDevice *self, + const gchar *attr, + guint64 *value, + GError **error) +{ + const gchar *tmp; + guint64 tmp64; + + g_return_val_if_fail(FU_IS_UDEV_DEVICE(self), FALSE); + g_return_val_if_fail(attr != NULL, FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); + + tmp = fu_udev_device_get_sysfs_attr(self, attr, error); + if (tmp == NULL) + return FALSE; + tmp64 = fu_common_strtoull(tmp); + if (value != NULL) + *value = tmp64; + return TRUE; +} + /** * fu_udev_device_pread: * @self: a #FuUdevDevice diff --git a/libfwupdplugin/fu-udev-device.h b/libfwupdplugin/fu-udev-device.h index 97c907f13..106a97cb5 100644 --- a/libfwupdplugin/fu-udev-device.h +++ b/libfwupdplugin/fu-udev-device.h @@ -115,6 +115,11 @@ fu_udev_device_pread_full(FuUdevDevice *self, GError **error) G_GNUC_WARN_UNUSED_RESULT; const gchar * fu_udev_device_get_sysfs_attr(FuUdevDevice *self, const gchar *attr, GError **error); +gboolean +fu_udev_device_get_sysfs_attr_uint64(FuUdevDevice *self, + const gchar *attr, + guint64 *value, + GError **error); gchar * fu_udev_device_get_parent_name(FuUdevDevice *self); diff --git a/libfwupdplugin/fwupdplugin.map b/libfwupdplugin/fwupdplugin.map index 9f7cf9c28..543a81736 100644 --- a/libfwupdplugin/fwupdplugin.map +++ b/libfwupdplugin/fwupdplugin.map @@ -949,5 +949,6 @@ LIBFWUPDPLUGIN_1.7.1 { LIBFWUPDPLUGIN_1.7.2 { global: fu_context_has_hwid_flag; + fu_udev_device_get_sysfs_attr_uint64; local: *; } LIBFWUPDPLUGIN_1.7.1;