summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2022-09-02 18:07:47 +0200
committerBastien Nocera <hadess@hadess.net>2022-09-05 10:34:36 +0200
commit6bfe66a390cbcbaa47ceb02b15514d20843dfc33 (patch)
tree0f469341073ffa152ea56cb69142b19a874423c8
parent5c8e74b76b5dd8f65fb54972f3ce23ebc411c51e (diff)
linux: Fix reading capacity_level with newer libgudev
Newer development versions of libgudev now strip the linefeeds by themselves, so fix our naive linefeed-stripping which munched on the last character of the string if there was no linefeed. Could not find a percentage for capacity level 'Ful' See https://gitlab.gnome.org/GNOME/libgudev/-/merge_requests/26
-rw-r--r--src/linux/up-device-supply.c5
1 files changed, 1 insertions, 4 deletions
diff --git a/src/linux/up-device-supply.c b/src/linux/up-device-supply.c
index 7cf452a..604ff54 100644
--- a/src/linux/up-device-supply.c
+++ b/src/linux/up-device-supply.c
@@ -215,7 +215,6 @@ sysfs_get_capacity_level (GUdevDevice *native,
{ "Full", 100.0, UP_DEVICE_LEVEL_FULL },
{ "Unknown", 50.0, UP_DEVICE_LEVEL_UNKNOWN }
};
- guint len;
g_return_val_if_fail (level != NULL, -1.0);
@@ -226,14 +225,12 @@ sysfs_get_capacity_level (GUdevDevice *native,
}
*level = UP_DEVICE_LEVEL_UNKNOWN;
- str = g_strdup (g_udev_device_get_sysfs_attr_uncached (native, "capacity_level"));
+ str = g_strchomp (g_strdup (g_udev_device_get_sysfs_attr_uncached (native, "capacity_level")));
if (!str) {
g_debug ("Failed to read capacity_level!");
return ret;
}
- len = strlen(str);
- str[len -1] = '\0';
for (i = 0; i < G_N_ELEMENTS(levels); i++) {
if (strcmp (levels[i].str, str) == 0) {
ret = levels[i].percentage;