chiark / gitweb /
libudev: use 4096 bytes buffer for attribute reading
[elogind.git] / udev / lib / libudev-device.c
index a25716d95d58d323dbf2bbf182dc93261f4993cc..fc881fb3fdacf27c5d194de6da0825254bc96df8 100644 (file)
@@ -541,33 +541,26 @@ struct udev_device *udev_device_get_parent(struct udev_device *udev_device)
        return udev_device->parent_device;
 }
 
-struct udev_device *udev_device_get_parent_with_subsystem(struct udev_device *udev_device, const char *subsystem)
+struct udev_device *udev_device_get_parent_with_subsystem_devtype(struct udev_device *udev_device, const char *subsystem, const char *devtype)
 {
        struct udev_device *parent;
 
-       parent = udev_device_get_parent(udev_device);
-       while (parent != NULL) {
-               const char *parent_subsystem;
-
-               parent_subsystem = udev_device_get_subsystem(parent);
-               if (parent_subsystem != NULL && strcmp(parent_subsystem, subsystem) == 0)
-                       break;
-               parent = udev_device_get_parent(parent);
-       }
-       return parent;
-}
-
-struct udev_device *udev_device_get_parent_with_devtype(struct udev_device *udev_device, const char *devtype)
-{
-       struct udev_device *parent;
+       if (subsystem == NULL)
+               return NULL;
 
        parent = udev_device_get_parent(udev_device);
        while (parent != NULL) {
+               const char *parent_subsystem;
                const char *parent_devtype;
 
-               parent_devtype = udev_device_get_devtype(parent);
-               if (parent_devtype != NULL && strcmp(parent_devtype, devtype) == 0)
-                       break;
+               parent_subsystem = udev_device_get_subsystem(parent);
+               if (parent_subsystem != NULL && strcmp(parent_subsystem, subsystem) == 0) {
+                       if (devtype == NULL)
+                               break;
+                       parent_devtype = udev_device_get_devtype(parent);
+                       if (parent_devtype != NULL && strcmp(parent_devtype, devtype) == 0)
+                               break;
+               }
                parent = udev_device_get_parent(parent);
        }
        return parent;
@@ -869,7 +862,7 @@ const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const
 {
        struct udev_list_entry *list_entry;
        char path[UTIL_PATH_SIZE];
-       char value[UTIL_NAME_SIZE];
+       char value[4096];
        struct stat statbuf;
        int fd;
        ssize_t size;
@@ -1066,6 +1059,20 @@ struct udev_list_entry *udev_device_add_property_from_string(struct udev_device
        return udev_device_add_property(udev_device, name, val);
 }
 
+const char *udev_device_get_property_value(struct udev_device *udev_device, const char *key)
+{
+       struct udev_list_entry *list_entry;
+
+       if (udev_device == NULL)
+               return NULL;
+       if (key == NULL)
+               return NULL;
+
+       list_entry = udev_device_get_properties_list_entry(udev_device);
+       list_entry =  udev_list_entry_get_by_name(list_entry, key);
+       return udev_list_entry_get_value(list_entry);
+}
+
 #define ENVP_SIZE                      128
 #define MONITOR_BUF_SIZE               4096
 static int update_envp_monitor_buf(struct udev_device *udev_device)