diff options
author | Kay Sievers <kay.sievers@vrfy.org> | 2008-09-10 14:29:07 +0200 |
---|---|---|
committer | Kay Sievers <kay.sievers@vrfy.org> | 2008-09-10 14:29:07 +0200 |
commit | b21b95d7222f32940c8e9462c361e45041c9f7d6 (patch) | |
tree | d75a22dd0617cabc0c655e70d50ce5a03b80a683 /udev/lib/libudev-utils.c | |
parent | e88a82b5976b8066583936a2521ba3c70dd460dd (diff) |
libudev: get rid of udev_sysfs.c
Diffstat (limited to 'udev/lib/libudev-utils.c')
-rw-r--r-- | udev/lib/libudev-utils.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/udev/lib/libudev-utils.c b/udev/lib/libudev-utils.c index 82acb1a481..e5f1ed7c38 100644 --- a/udev/lib/libudev-utils.c +++ b/udev/lib/libudev-utils.c @@ -63,3 +63,34 @@ ssize_t util_get_sys_driver(struct udev *udev, const char *devpath, char *driver return get_sys_link(udev, "driver", devpath, driver, size); } +int util_resolve_sys_link(struct udev *udev, char *devpath, size_t size) +{ + char link_path[PATH_SIZE]; + char link_target[PATH_SIZE]; + int len; + int i; + int back; + + strlcpy(link_path, udev_get_sys_path(udev), sizeof(link_path)); + strlcat(link_path, devpath, sizeof(link_path)); + len = readlink(link_path, link_target, sizeof(link_target)); + if (len <= 0) + return -1; + link_target[len] = '\0'; + dbg(udev, "path link '%s' points to '%s'\n", devpath, link_target); + + for (back = 0; strncmp(&link_target[back * 3], "../", 3) == 0; back++) + ; + dbg(udev, "base '%s', tail '%s', back %i\n", devpath, &link_target[back * 3], back); + for (i = 0; i <= back; i++) { + char *pos = strrchr(devpath, '/'); + + if (pos == NULL) + return -1; + pos[0] = '\0'; + } + dbg(udev, "after moving back '%s'\n", devpath); + strlcat(devpath, "/", size); + strlcat(devpath, &link_target[back * 3], size); + return 0; +} |