udev: add helper udev_device_new_from_stat_rdev()
This is a simple wrapper around udev_device_new_from_devnum(), and uses the data from a struct stat's .st_rdev field to derive the udev_device object.
This commit is contained in:
@@ -42,3 +42,26 @@ int udev_parse_config(void) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int udev_device_new_from_stat_rdev(struct udev *udev, const struct stat *st, struct udev_device **ret) {
|
||||
struct udev_device *nd;
|
||||
char type;
|
||||
|
||||
assert(udev);
|
||||
assert(st);
|
||||
assert(ret);
|
||||
|
||||
if (S_ISBLK(st->st_mode))
|
||||
type = 'b';
|
||||
else if (S_ISCHR(st->st_mode))
|
||||
type = 'c';
|
||||
else
|
||||
return -ENOTTY;
|
||||
|
||||
nd = udev_device_new_from_devnum(udev, type, st->st_rdev);
|
||||
if (!nd)
|
||||
return -errno;
|
||||
|
||||
*ret = nd;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -21,3 +21,5 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_ctrl_msg*, udev_ctrl_msg_unref);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_monitor*, udev_monitor_unref);
|
||||
|
||||
int udev_parse_config(void);
|
||||
|
||||
int udev_device_new_from_stat_rdev(struct udev *udev, const struct stat *st, struct udev_device **ret);
|
||||
|
||||
Reference in New Issue
Block a user