diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2019-06-12 06:03:19 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2019-06-12 16:55:26 +0200 |
commit | dcf557f7b04a3c5202ddbafca06311a12442fd4c (patch) | |
tree | 8f5b42f34cca3690d140ca68052f17d19298d420 /src/libudev/libudev-enumerate.c | |
parent | libudev: drop unused variable (diff) | |
download | systemd-dcf557f7b04a3c5202ddbafca06311a12442fd4c.tar.xz systemd-dcf557f7b04a3c5202ddbafca06311a12442fd4c.zip |
libudev: hide definition of struct udev_list from other libudev components
In the later commit, udev_list will be just a wrapper of hashmap or LIST.
So, allocating udev_list does not increase much cost.
Diffstat (limited to 'src/libudev/libudev-enumerate.c')
-rw-r--r-- | src/libudev/libudev-enumerate.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/libudev/libudev-enumerate.c b/src/libudev/libudev-enumerate.c index 80d5bafdf7..481c90df10 100644 --- a/src/libudev/libudev-enumerate.c +++ b/src/libudev/libudev-enumerate.c @@ -34,7 +34,7 @@ struct udev_enumerate { struct udev *udev; unsigned n_ref; - struct udev_list devices_list; + struct udev_list *devices_list; bool devices_uptodate:1; sd_device_enumerator *enumerator; @@ -50,6 +50,7 @@ struct udev_enumerate { **/ _public_ struct udev_enumerate *udev_enumerate_new(struct udev *udev) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; + _cleanup_(udev_list_freep) struct udev_list *list = NULL; struct udev_enumerate *udev_enumerate; int r; @@ -61,6 +62,10 @@ _public_ struct udev_enumerate *udev_enumerate_new(struct udev *udev) { if (r < 0) return_with_errno(NULL, r); + list = udev_list_new(false); + if (!list) + return_with_errno(NULL, ENOMEM); + udev_enumerate = new(struct udev_enumerate, 1); if (!udev_enumerate) return_with_errno(NULL, ENOMEM); @@ -69,17 +74,16 @@ _public_ struct udev_enumerate *udev_enumerate_new(struct udev *udev) { .udev = udev, .n_ref = 1, .enumerator = TAKE_PTR(e), + .devices_list = TAKE_PTR(list), }; - udev_list_init(&udev_enumerate->devices_list, false); - return udev_enumerate; } static struct udev_enumerate *udev_enumerate_free(struct udev_enumerate *udev_enumerate) { assert(udev_enumerate); - udev_list_cleanup(&udev_enumerate->devices_list); + udev_list_free(udev_enumerate->devices_list); sd_device_enumerator_unref(udev_enumerate->enumerator); return mfree(udev_enumerate); } @@ -134,7 +138,7 @@ _public_ struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enume if (!udev_enumerate->devices_uptodate) { sd_device *device; - udev_list_cleanup(&udev_enumerate->devices_list); + udev_list_cleanup(udev_enumerate->devices_list); FOREACH_DEVICE_AND_SUBSYSTEM(udev_enumerate->enumerator, device) { const char *syspath; @@ -144,14 +148,14 @@ _public_ struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enume if (r < 0) return_with_errno(NULL, r); - if (!udev_list_entry_add(&udev_enumerate->devices_list, syspath, NULL)) + if (!udev_list_entry_add(udev_enumerate->devices_list, syspath, NULL)) return_with_errno(NULL, ENOMEM); } udev_enumerate->devices_uptodate = true; } - e = udev_list_get_entry(&udev_enumerate->devices_list); + e = udev_list_get_entry(udev_enumerate->devices_list); if (!e) return_with_errno(NULL, ENODATA); |