/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
+#include <dirent.h>
#include <inttypes.h>
#include <stdbool.h>
#include <sys/stat.h>
int device_new_from_nulstr(sd_device **ret, char *nulstr, size_t len);
int device_new_from_strv(sd_device **ret, char **strv);
+int device_opendir(sd_device *device, const char *subdir, DIR **ret);
+
int device_get_property_bool(sd_device *device, const char *key);
int device_get_sysattr_unsigned(sd_device *device, const char *sysattr, unsigned *ret_value);
int device_get_sysattr_bool(sd_device *device, const char *sysattr);
return TAKE_FD(fd2);
}
+
+int device_opendir(sd_device *device, const char *subdir, DIR **ret) {
+ _cleanup_closedir_ DIR *d = NULL;
+ _cleanup_free_ char *path = NULL;
+ const char *syspath;
+ int r;
+
+ assert(device);
+ assert(ret);
+
+ r = sd_device_get_syspath(device, &syspath);
+ if (r < 0)
+ return r;
+
+ if (subdir) {
+ if (!path_is_safe(subdir))
+ return -EINVAL;
+
+ path = path_join(syspath, subdir);
+ if (!path)
+ return -ENOMEM;
+ }
+
+ d = opendir(path ?: syspath);
+ if (!d)
+ return -errno;
+
+ *ret = TAKE_PTR(d);
+ return 0;
+}