diff options
Diffstat (limited to 'udev/lib/libudev-utils.c')
-rw-r--r-- | udev/lib/libudev-utils.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/udev/lib/libudev-utils.c b/udev/lib/libudev-utils.c new file mode 100644 index 0000000000..8251b64da9 --- /dev/null +++ b/udev/lib/libudev-utils.c @@ -0,0 +1,53 @@ +/* + * libudev - interface to udev device information + * + * Copyright (C) 2008 Kay Sievers <kay.sievers@vrfy.org> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "config.h" + +#include <stdio.h> +#include <stdlib.h> +#include <stddef.h> +#include <unistd.h> +#include <errno.h> +#include <string.h> +#include <dirent.h> +#include <sys/stat.h> + +#include "libudev.h" +#include "libudev-private.h" +#include "../udev.h" + +ssize_t util_get_sys_subsystem(struct udev *udev, const char *devpath, char *subsystem, size_t size) +{ + char path[PATH_SIZE]; + ssize_t len; + const char *pos; + + strlcpy(path, udev_get_sys_path(udev), sizeof(path)); + strlcat(path, devpath, sizeof(path)); + strlcat(path, "/subsystem", sizeof(path)); + len = readlink(path, path, sizeof(path)); + if (len < 0 || len >= (ssize_t) sizeof(path)) + return -1; + path[len] = '\0'; + pos = strrchr(path, '/'); + if (pos == NULL) + return -1; + pos = &pos[1]; + return strlcpy(subsystem, pos, size); +} |