/*
* Function Prototypes
*/
+extern int sysfs_trailing_slash(unsigned char *path);
extern int sysfs_get_mnt_path(unsigned char *mnt_path, size_t len);
extern int sysfs_get_name_from_path(const unsigned char *path,
unsigned char *name, size_t len);
return NULL;
}
- strcat(buspath, SYSFS_BUS_DIR);
+ if (sysfs_trailing_slash(buspath) == 0)
+ strcat(buspath, "/");
+
+ strcat(buspath, SYSFS_BUS_NAME);
strcat(buspath, "/");
strcat(buspath, name);
busdir = sysfs_open_directory(buspath);
return NULL;
}
- strcat(path, SYSFS_BUS_DIR);
+ if (sysfs_trailing_slash(path) == 0)
+ strcat(path, "/");
+ strcat(path, SYSFS_BUS_NAME);
strcat(path, "/");
strcat(path, busname);
- strcat(path, SYSFS_DEVICES_DIR);
+ strcat(path, "/");
+ strcat(path, SYSFS_DEVICES_NAME);
strcat(path, "/");
strcat(path, dev_id);
}
memset(subsys, 0, SYSFS_PATH_MAX);
- strcpy(subsys, SYSFS_BUS_DIR);
+ strcpy(subsys, SYSFS_BUS_NAME);
buslist = sysfs_open_subsystem_list(subsys);
if (buslist != NULL) {
dlist_for_each_data(buslist, bus, char) {
memset(subsys, 0, SYSFS_PATH_MAX);
- strcpy(subsys, SYSFS_BUS_DIR);
+ strcat(subsys, "/");
+ strcpy(subsys, SYSFS_BUS_NAME);
strcat(subsys, "/");
strcat(subsys, bus);
- strcat(subsys, SYSFS_DRIVERS_DIR);
+ strcat(subsys, "/");
+ strcat(subsys, SYSFS_DRIVERS_NAME);
drivers = sysfs_open_subsystem_list(subsys);
if (drivers != NULL) {
dlist_for_each_data(drivers, curdrv, char) {
return NULL;
}
+ if (sysfs_trailing_slash(classpath) == 0)
+ strcat(classpath, "/");
/*
* We shall now treat "block" also as a class. Hence, check here
* if "name" is "block" and proceed accordingly
*/
if (strcmp(name, SYSFS_BLOCK_NAME) == 0) {
- strcat(classpath, SYSFS_BLOCK_DIR);
+ strcat(classpath, SYSFS_BLOCK_NAME);
} else {
- strcat(classpath, SYSFS_CLASS_DIR);
+ strcat(classpath, SYSFS_CLASS_NAME);
strcat(classpath, "/");
strcat(classpath, name);
}
dprintf("Error getting sysfs mount path\n");
return -1;
}
+ if (sysfs_trailing_slash(path) == 0)
+ strcat(path, "/");
+
if (strcmp(classname, SYSFS_BLOCK_NAME) == 0) {
- strcat(path, SYSFS_BLOCK_DIR);
+ strcat(path, SYSFS_BLOCK_NAME);
} else {
- strcat(path, SYSFS_CLASS_DIR);
+ strcat(path, SYSFS_CLASS_NAME);
strcat(path, "/");
strcat(path, classname);
}
if (sysfs_get_mnt_path(devpath, SYSFS_PATH_MAX) != 0)
return -1;
- strcat(devpath, SYSFS_BUS_DIR);
+ if (sysfs_trailing_slash(devpath) == 0)
+ strcat(devpath, "/");
+ strcat(devpath, SYSFS_BUS_NAME);
strcat(devpath, "/");
strcat(devpath, busname);
strcat(devpath, SYSFS_DEVICES_DIR);
return NULL;
}
- strcat(rootpath, SYSFS_DEVICES_DIR);
+ if (sysfs_trailing_slash(rootpath) == 0)
+ strcat(rootpath, "/");
+
+ strcat(rootpath, SYSFS_DEVICES_NAME);
strcat(rootpath, "/");
strcat(rootpath, name);
rdir = sysfs_open_directory(rootpath);
dprintf ("Sysfs not supported on this system\n");
return -1;
}
- strcat(bus_path, SYSFS_BUS_DIR);
+ if (sysfs_trailing_slash(bus_path) == 0)
+ strcat(bus_path, "/");
+ strcat(bus_path, SYSFS_BUS_NAME);
strcat(bus_path, "/");
strcat(bus_path, bus);
strcat(bus_path, SYSFS_DEVICES_DIR);
dprintf("Error getting sysfs mount path\n");
return -1;
}
- strcat(path, SYSFS_BUS_DIR);
+ if (sysfs_trailing_slash(path) == 0)
+ strcat(path, "/");
+ strcat(path, SYSFS_BUS_NAME);
strcat(path, "/");
strcat(path, bus);
strcat(path, SYSFS_DRIVERS_DIR);
#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
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) {
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);