X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=libsysfs%2Fsysfs_utils.c;h=627e618dceaf699dd811e091e09980126d4e711f;hp=4e96051c780452809f087efb52bf543f3855b021;hb=edcd336477880368915245a4b7ddd1bca5940b30;hpb=bc1530c65c282e27eb60de797291ca45c2d8cda2 diff --git a/libsysfs/sysfs_utils.c b/libsysfs/sysfs_utils.c index 4e96051c7..627e618dc 100644 --- a/libsysfs/sysfs_utils.c +++ b/libsysfs/sysfs_utils.c @@ -76,6 +76,23 @@ static int sysfs_get_fs_mnt_path(const unsigned char *fs_type, #endif } +/* + * sysfs_trailing_slash: checks if there's a trailing slash to path + * @path: path to check + * returns 1 if true and 0 if not + */ +int sysfs_trailing_slash(unsigned char *path) +{ + unsigned char *s = NULL; + + if (path == NULL) + return 0; + s = &path[strlen(path)-1]; + if (strncmp(s, "/", 1) == 0) + return 1; + return 0; +} + /* * sysfs_get_mnt_path: Gets the sysfs mount point. * @mnt_path: place to put "sysfs" mount point @@ -226,6 +243,8 @@ struct dlist *sysfs_open_subsystem_list(unsigned char *name) return NULL; } + if (sysfs_trailing_slash(sysfs_path) == 0) + strcat(sysfs_path, "/"); strcat(sysfs_path, name); dir = sysfs_open_directory(sysfs_path); if (dir == NULL) { @@ -301,7 +320,9 @@ struct dlist *sysfs_open_bus_devices_list(unsigned char *name) return NULL; } - strcat(sysfs_path, SYSFS_BUS_DIR); + if (sysfs_trailing_slash(sysfs_path) == 0) + strcat(sysfs_path, "/"); + strcat(sysfs_path, SYSFS_BUS_NAME); strcat(sysfs_path, "/"); strcat(sysfs_path, name); strcat(sysfs_path, SYSFS_DEVICES_DIR);