]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/udev/udevadm-util.c
pkgconfig: define variables relative to ${prefix}/${rootprefix}/${sysconfdir}
[thirdparty/systemd.git] / src / udev / udevadm-util.c
1 /* SPDX-License-Identifier: GPL-2.0+ */
2
3 #include <errno.h>
4
5 #include "alloc-util.h"
6 #include "device-private.h"
7 #include "path-util.h"
8 #include "udevadm-util.h"
9
10 int find_device(const char *id, const char *prefix, sd_device **ret) {
11 _cleanup_free_ char *buf = NULL;
12
13 assert(id);
14 assert(ret);
15
16 if (prefix && !path_startswith(id, prefix)) {
17 buf = path_join(NULL, prefix, id);
18 if (!buf)
19 return -ENOMEM;
20 id = buf;
21 }
22
23 if (path_startswith(id, "/sys/"))
24 return sd_device_new_from_syspath(ret, id);
25
26 if (path_startswith(id, "/dev/")) {
27 struct stat st;
28
29 if (stat(id, &st) < 0)
30 return -errno;
31
32 return device_new_from_stat_rdev(ret, &st);
33 }
34
35 return -EINVAL;
36 }