udev_device.c: use strrchr to trim newline

This commit is contained in:
illiliti
2021-06-06 09:14:56 +03:00
parent 75a40e1040
commit 34f8727f28

View File

@@ -243,6 +243,7 @@ const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const
struct stat st;
size_t len;
FILE *file;
char *pos;
if (!udev_device || !sysattr) {
return NULL;
@@ -277,9 +278,8 @@ const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const
fclose(file);
data[len] = '\0';
// TODO strrchr?
while (len-- > 0 && data[len] == '\n') {
data[len] = '\0';
if ((pos = strrchr(data, '\n'))) {
*pos = '\0';
}
list_entry = udev_list_entry_add(&udev_device->sysattrs, sysattr, data, 0);