+/* SPDX-License-Identifier: LGPL-2.1+ */
/***
This file is part of systemd.
Copyright 2008-2012 Kay Sievers <kay@vrfy.org>
Copyright 2015 Tom Gundersen <teg@jklm.no>
-
- systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- systemd is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <dirent.h>
**/
_public_ struct udev_enumerate *udev_enumerate_new(struct udev *udev) {
_cleanup_free_ struct udev_enumerate *udev_enumerate = NULL;
- struct udev_enumerate *ret;
int r;
assert_return_errno(udev, NULL, EINVAL);
udev_list_init(udev, &udev_enumerate->devices_list, false);
- ret = udev_enumerate;
- udev_enumerate = NULL;
-
- return ret;
+ return TAKE_PTR(udev_enumerate);
}
/**
**/
_public_ struct udev_enumerate *udev_enumerate_ref(struct udev_enumerate *udev_enumerate) {
if (udev_enumerate)
- udev_enumerate->refcount ++;
+ udev_enumerate->refcount++;
return udev_enumerate;
}
* Returns: a udev_list_entry.
*/
_public_ struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *udev_enumerate) {
+ struct udev_list_entry *e;
+
assert_return_errno(udev_enumerate, NULL, EINVAL);
if (!udev_enumerate->devices_uptodate) {
udev_enumerate->devices_uptodate = true;
}
- return udev_list_get_entry(&udev_enumerate->devices_list);
+ e = udev_list_get_entry(&udev_enumerate->devices_list);
+ if (!e)
+ errno = ENODATA;
+
+ return e;
}
/**
* Returns: 0 on success, otherwise a negative error value.
*/
_public_ int udev_enumerate_add_syspath(struct udev_enumerate *udev_enumerate, const char *syspath) {
- _cleanup_device_unref_ sd_device *device = NULL;
+ _cleanup_(sd_device_unrefp) sd_device *device = NULL;
int r;
assert_return(udev_enumerate, -EINVAL);